如何在Android中使用facebook sdk 4.0获取Facebook Feeds(帖子)?

时间:2015-06-19 14:20:57

标签: android facebook-sdk-4.0

我在may应用程序中显示了facebook feed(post)列表。我正在使用Facebook 4.0我能够获取个人资料但无法获取我的所有提要(帖子)。如果有人有任何参考,请告诉我。感谢。

现在我正在使用以下代码来获取Feed,但获得空白响应,例如{" data":[]}

FacebookCallback<LoginResult> facebookCallback = new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {

            new GraphRequest(
                     AccessToken.getCurrentAccessToken(),
                     loginResult.getAccessToken().getUserId()+"/feed/",
                     null,
                     HttpMethod.GET,
                     new GraphRequest.Callback() {
                         public void onCompleted(GraphResponse response) {
                             Log.i("fb", "Feeds :" +response.getJSONObject());
                             Toast.makeText(
                                     getApplicationContext(),
                                     response.getJSONObject()
                                             + "",
                                     Toast.LENGTH_SHORT).show();
                         }
                     }
             ).executeAsync();

    }

3 个答案:

答案 0 :(得分:1)

答案 1 :(得分:1)

下面,

您没有传递以下参数:

Bundle params = new Bundle();
        params.putString("fields", "message,created_time,id,full_picture,status_type,source,comments.summary(true),likes.summary(true)");
        params.putString("limit", "10");


/* make the API call */
        new GraphRequest(AccessToken.getCurrentAccessToken(), "/userId/posts", params, HttpMethod.GET,
                new GraphRequest.Callback() {
                    public void onCompleted(GraphResponse response) {
                        /* handle the result */
                        System.out.println("Festival Page response::" + String.valueOf(response.getJSONObject()));

                        try {
                            JSONObject jObjResponse = new JSONObject(String.valueOf(response.getJSONObject()));
                        }
                        catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }
        ).executeAsync();

希望解决这些问题我正在解决 facebook SDK 4.6.0

答案 2 :(得分:0)

您应该为登录请求添加user_posts权限:

LoginManager.getInstance().logInWithReadPermissions(this,
Arrays.asList("public_profile ", "user_status","user_posts"));