Get a Facebook Page's public posts without an

2019-08-08 05:08发布

问题:

Is it possible (using the facebook graph API) to get the last 5 posts made by a Facebook Page?

I would like to display this information in an Android app and want to avoid the overhead of using the Facebook Android SDK to avoid showing the "[App] would like to access your public profile and friend list" message because it's annoying and inaccurate.

The following call works without an auth token for example: https://graph.facebook.com/nike

But this one doesn't: https://graph.facebook.com/nike/posts

{
   "error": {
      "message": "An access token is required to request this resource.",
      "type": "OAuthException",
      "code": 104
   }
}

I could scrape the HTML off of this page without an auth token but this seems like overkill for such a simple task: https://www.facebook.com/nike/posts

To summarize:

  1. Is this really a limitation of the API?

  2. Is there a way to suppress the "[App] would like to access your public profile and friend list" message when acquiring an auth-token with no extra permissions using the Android SDK?

  3. Is it perhaps possible using a server-side SDK?

EDIT: Looks like the best way to do this is server-side with a long-lived App Access token.

回答1:

Is this really a limitation of the API?

No.

Is there a way to suppress the "[App] would like to access your public profile and friend list" message when acquiring an auth-token with no extra permissions using the Android SDK?

Yes. If you read the documentation properly (Post), its clearly mentioned that any valid access token is required to fetch the details* of the posts of a page. So, you could use the App access token, which you could get without any authorization step- from here or a simple GET request (server-side)-

GET /oauth/access_token?
client_id={app-id}
&client_secret={app-secret}
&grant_type=client_credentials

Is it perhaps possible using a server-side SDK?

Depends on you, how you want to implement.

*Note: Of course, the posts that you can see would be the public posts only (that could be seen even if a user is logged-out); else you might require user authentication with read_stream permission.