将图像从Android发布到Facebook页面

问题描述:

我已成功通过图表api在Facebook页面中发布了供稿.

I have successfully post a feed in facebook page form the graph api.

     try {
                   resObj.put("message","feed from android");
//resObj.put("object_attachment",bitmap);

                } catch (JSONException e) {
                    e.printStackTrace();
                }

                GraphRequest request = GraphRequest.newPostRequest(
                        AccessToken.getCurrentAccessToken(),"363453267193844/photos",resObj,
                        new GraphRequest.Callback() {
                            @Override
                            public void onCompleted(GraphResponse graphResponse) {
                                Log.i(TAG,"post page response::"+graphResponse);

                            }
                        }
                    );

                request.executeAsync();

但是,我无法将图像发布到Facebook页面.问题是我在Graph Api中发布的Json数据中找不到图像附件的密钥.

But, I'm unable to post image into facebook page. The problem is I'm unable to find the key for image attachment in Json data posted in Graph Api.

facebook失败的响应是

The failed response from facebook is

{Response:  responseCode: 400, graphObject: null, error: {HttpStatus: 400, errorCode: 324, errorType: OAuthException, errorMessage: (#324) Requires upload file}}

最后,最后,我能够将图像发布到Facebook页面中.这就是我发布照片的方式.

Finally, finally, I was able to post an image into facebook page. This is how I did to post an photo.

  Bundle bundle=new Bundle();
        bundle.putByteArray("object_attachment",byteArray);// object attachment must be either byteArray or bitmap image
        bundle.putString("message","some message here");

        GraphRequest graphRequest=new GraphRequest(AccessToken.getCurrentAccessToken(),
                "{page_id}/photos",
                bundle,
                HttpMethod.POST,
                new GraphRequest.Callback() {

                    @Override
                    public void onCompleted(GraphResponse graphResponse) {

                      Log.i("post page response::" + graphResponse);

                }
        );
        graphRequest.executeAsync();