Dom Shahbazi
Dom Shahbazi

Reputation: 730

How to use cursor-based pagination with Android Facebook API

I am trying to retrieve items from my Facebook news feed using the graph API. The code (unfinished) I am using is below, which seems to only be returning a single news feed post. I have read the documentation on cursor based pagination but it does not explain how to implement it, nor have i found any other resources explaining this matter.

// 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();
    }

As I am still experimenting, I am just trying to pull down 5 news feed items and output the message JSON attribute. Could anybody advise me on how to properly implement the cursor based pagination to pull down an arbitrary number of feed posts at a time? Thanks

Upvotes: 0

Views: 900

Answers (2)

Frank D
Frank D

Reputation: 612

The person in your link is using FB-Andriod-SDK 3.0.1 Source

Which means it is using Graph v1.0

FB-Andriod-SDK 3.8 and above started using Graph v2.0

In Graph v2.0 and above the ability to use the "read_stream" permission became severely limited. So much so that unless you are a Facebook engineer you won't get it.

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"

The user/home edge requires "read_stream" (user is a place holder for a User ID or "Me" keyword)

Permissions

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

Source

This also extents to user/feed edge

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

As well as user/posts edge

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

Source

On April 30, 2015 Graph v1.0 will be completely gone.

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"

More insightful information about this can be found here. Read all the comments Emil (FB Engineer) and Simon (Graph Product Manger) are the best sources

So what it boils down to is. You are attempting to do something that the Facebook developed app already does and they don't want you to do it.

Upvotes: 1

Frank D
Frank D

Reputation: 612

First of all you can not use "me/home" as a call. It requires the "read_stream" permission and you'll never get that approved.

There is really no way to get this data on your own. You'll have to use one of FB's Media Partners

Here is more info. Click here for more info

Upvotes: 0

Related Questions