使用facebook SDk 4.0将图像发布到facebook失败

时间:2016-05-31 09:35:26

标签: android facebook facebook-graph-api facebook-sdk-4.x

我正在开发一个Android应用程序,并希望从我的应用程序分享图像到Facebook但没有显示对话框,我尝试如下,但它没有工作。可以有人帮助我吗?

public void postFb(){ String path = "me/feed";
        AccessToken at = AccessToken.getCurrentAccessToken();
        Bundle parameters = new Bundle();
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        Const.bmp_post.compress(Bitmap.CompressFormat.PNG, 100, stream);
        byte[] byteArray = stream.toByteArray();
        parameters.putByteArray("picture", byteArray);
        HttpMethod method = HttpMethod.POST;
        GraphRequest.Callback cb = new GraphRequest.Callback() {

            @Override
            public void onCompleted(GraphResponse graphResponse) {
                Log.d("=======graph response=======" , graphResponse.toString());
                //check graphResponse for success or failure
                if(graphResponse.getError()==null){

                    Toast.makeText(NewPostActivity.this, "Successfully posted to Facebook", Toast.LENGTH_SHORT).show();
                }
                else{
                    Toast.makeText(NewPostActivity.this, "Facebook: There was an error, Please Try Again", Toast.LENGTH_SHORT).show();

                }
            }
        };

        GraphRequest request = new GraphRequest(at,path,parameters,method,cb);
        request.setParameters(parameters);
        request.executeAsync();
    }

1 个答案:

答案 0 :(得分:0)

< p>尝试更改< code>" / me / feed"< / code>到< code>" me / photos"< / code>< / p>