用facebook sdk在墙上发布照片

时间:2013-06-28 17:10:09

标签: android facebook facebook-graph-api post


我正在尝试使用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:null,error:{HttpStatus:400,errorCode:324,errorType:   OAuthException,errorMessage:(#324)需要上传文件},   isFromCache:假}


我试过没有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中添加评论......

它可能是什么?
谢谢你的时间。

1 个答案:

答案 0 :(得分:5)

终于开始工作!!!

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

希望它也能帮到你;)