在Facebook上使用Facebook-sdk错误在Facebook上发布图片

时间:2014-03-07 08:20:15

标签: android facebook facebook-graph-api

我尝试使用facebook-sdk在Facebook墙上发布图片。但它不发布图片。它说跟随错误。

03-07 13:40:25.412: W/com.facebook.Session(12186): Should not pass a read permission (user_photos,publish_checkins,publish_actions,publish_stream) to a request for publish or manage authorization

这是我的活动代码。

btn=(Button) findViewById(R.id.button1);

        btn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                facebook.authorize(MainActivity.this, new String[]{ "user_photos,publish_checkins,publish_actions,publish_stream"},new DialogListener() {
                    @Override
                    public void onComplete(Bundle values) {
                        postImage();
                        Toast.makeText(getApplicationContext(), "Image Posted on Facebook.", Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onFacebookError(FacebookError error) {
                    }

                    @Override
                    public void onError(DialogError e) {
                    }

                    @Override
                    public void onCancel() {
                    }

                });
            }  
        });
    }


    public void postImage(){
         byte[] data = null;               

           Bitmap bi = BitmapFactory.decodeFile("/Pictures/test.jpg");            
            ByteArrayOutputStream baos = new ByteArrayOutputStream();              
           bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);              
            data = baos.toByteArray();                
            Bundle params = new Bundle();              
            params.putString(Facebook.TOKEN, facebook.getAccessToken());              
            params.putString("method", "photos.upload");              
            params.putByteArray("picture", data);               
            AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);   

****Edited****           
            mAsyncRunner.request("me/posts", params, "POST", new SampleUploadListener(), null);   

    }


    public class SampleUploadListener extends BaseKeyListener implements RequestListener {

        public void onComplete(final String response, final Object state) {
            try {
                Log.d("Facebook-Example", "Response: " + response.toString());
                JSONObject json = Util.parseJson(response);
                final String src = json.getString("src");
            } catch (JSONException e) {
                Log.w("Facebook-Example", "JSON Error in response");
            } catch (FacebookError e) {
                Log.w("Facebook-Example", "Facebook Error: " + e.getMessage());
            }
        }

1 个答案:

答案 0 :(得分:0)

根据你想要做的事情,你需要给这行代码一个目标(第一个空):

mAsyncRunner.request(null, params, "POST", new SampleUploadListener(), null);

例如,如果您尝试在当前用户墙上发帖,则应该如下所示:

mAsyncRunner.request("me/posts", params, "POST", new SampleUploadListener(), null);
You will need the correct permissions to do this: at least publish_stream.