将图像从Android发布到Facebook页面 [英] Post image from android to facebook page

查看:80
本文介绍了将图像从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();

这篇关于将图像从Android发布到Facebook页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆