【问题标题】:Publish photo on wall with facebook sdk使用 facebook sdk 在墙上发布照片
【发布时间】:2013-06-28 17:10:09
【问题描述】:


我正在尝试使用 facebook sdk 3.0 for android 在我的墙上发布一张照片。 代码如下:

    GraphObject graphObject = GraphObject.Factory.create();

    Bitmap bmp = BitmapFactory.decodeFile(loadFinalImageSavedFullPath());
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
    byte[] byteArray = stream.toByteArray();

    graphObject.setProperty("source", Base64.encodeToString(byteArray, Base64.DEFAULT);
    graphObject.setProperty("message", "sup");

    com.facebook.Request.executePostRequestAsync(fSession, "me/photos", graphObject, new Callback() {...}

但我总是收到此错误:

I/facebook(10707): {响应: responseCode: 400, graphObject:空,错误:{HttpStatus:400,errorCode:324,errorType: OAuthException, errorMessage: (#324) 需要上传文件}, isFromCache:false}



我尝试在没有 facebook API 的情况下发布:

@Override
        protected Boolean doInBackground(String... params) {
            Bitmap bmp = BitmapFactory.decodeFile(loadFinalImageSavedFullPath());

            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
            byte[] byteArray = stream.toByteArray();

            List<NameValuePair> pm = new ArrayList<NameValuePair>();
            pm.add(new BasicNameValuePair("access_token", params[0]));
            pm.add(new BasicNameValuePair("message","sup"));
            pm.add(new BasicNameValuePair("source", Base64.encodeToString(byteArray, Base64.DEFAULT)));

            String res = postJSONString(https://graph.facebook.com/me/photos, pm);
            Log.i(TAG, res);
            if (res == null || res.contains("error")) {
                return false;
            }
            return true;
        }

同样的问题...

I/facebook(2977): {"error":{"message":"(#324) 需要上传 文件","类型":"OAuthException","代码":324}}


看起来这是我管理它工作的唯一方法:

com.facebook.Request.executeUploadPhotoRequestAsync(fSession, bmp, new Callback() {

缺点,不能在 POST 中添加评论...

可能是什么?
感谢您的宝贵时间。

【问题讨论】:

    标签: android facebook facebook-graph-api post


    【解决方案1】:

    终于搞定了!!!

    com.facebook.Request request = com.facebook.Request.newUploadPhotoRequest(Session.getActiveSession(), bmp, new Request.Callback() {...});
    
    Bundle params = request.getParameters();
    params.putString("name", "sup");
    request.setParameters(params);
    
    Request.executeBatchAsync(request);
    

    希望对你也有帮助;)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-17
      相关资源
      最近更新 更多