如何在 Android Facebook API 中使用基于光标的分页

How to use cursor-based pagination with Android Facebook API

我正在尝试使用图表 API 从我的 Facebook 新闻提要中检索项目。我正在使用的代码(未完成)如下,它似乎只返回一个新闻提要 post。我已经阅读了有关基于游标的分页的文档,但它没有解释如何实现它,也没有找到任何其他资源来解释这个问题。

// Get items from users news feed
    public void getFeed() {

        Session s = Session.getActiveSession();

        new Request(
                s,
                "/me/home",
                null,
                HttpMethod.GET,
                new Request.Callback() {
                    public void onCompleted(Response response) {
                        /* handle the result */

                        JSONArray json = null;
                        JSONObject current = null;

                        try {
                            json = (JSONArray)response.getGraphObject().getProperty("data");
                        } catch(Exception e) {
                            // TODO
                        }

                        for(int i=0; i<5; i++) {
                            try {
                                current = json.getJSONObject(i);
                                Log.d("Value: ", current.get("message").toString());
                            } catch(Exception e) {
                                // Nothing
                            }
                        }

                    }
                }
        ).executeAsync();
    }

因为我还在试验,我只是想拉下 5 个新闻提要项目并输出 message JSON 属性。有人能告诉我如何正确实施基于光标的分页以一次拉下任意数量的提要 posts 吗?谢谢

首先你不能使用"me/home"作为调用。它需要 "read_stream" 许可,您永远不会获得批准。

这些数据靠自己是真的没办法。你必须使用 FB 之一 Media Partners

这里有更多信息。 Click here for more info

你link中的人正在使用 FB-Andriod-SDK 3.0.1 Source

这意味着它正在使用 Graph v1.0

FB-Andriod-SDK 3.8及以上版本开始使用Graph v2.0

在 Graph v2.0 及更高版本中,使用“read_stream”权限的能力受到严重限制。如此之多,以至于除非你是 Facebook 工程师,否则你不会得到它。

Limited Use

  • This permission is granted to apps building a Facebook-branded client on platforms where Facebook is not already available. For example, Android and iOS apps will not be approved for this permission. In addition, Web, Desktop, in-car and TV apps will not be granted this permission.

Source, Scroll down to "read_stream"

user/home 边缘需要“read_stream”(用户是用户 ID 或“我”关键字的占位符)

Permissions

  • A user access token with read_stream permission is required to view that person's news feed.

Source

这也延伸到 user/feed 边缘

Permissions

  • Any valid access token is required to view public links.
  • A user access token with read_stream permission is required.
  • Only posts whose authors have also granted read_stream permission to the app will be shown.

Source

以及user/posts边

This is a duplicate of the /feed edge which only shows posts published by the person themselves.

Source

2015 年 4 月 30 日,Graph v1.0 将完全消失。

The current, latest version of the Graph API is v2.2. Apps calling v1.0 have until April 30, 2015 to upgrade to v2.0 or later.

Source, under "Staying up to date"

可以在此处找到有关此的更多有见地的信息。 Read all the comments Emil (FB Engineer) and Simon (Graph Product Manger) 是最好的来源

归根结底就是。您正在尝试做一些 Facebook 开发的应用程序已经做的事情,但他们不希望您做。