1


我正在尝试使用 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): {Response: responseCode: 400, graphObject: null, error: {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) 需要上传文件","type":"OAuthException","code":324}}


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

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

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

会是什么呢?
谢谢你的时间。

4

1 回答 1

4

终于开工了!!!

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);

希望它对你也有帮助;)

于 2013-07-04T15:30:12.787 回答