john johnson
john johnson

Reputation: 11

How do I use an user access token to with the Facebook graph api? (PHP)

I don't have any issue getting my access token:

$accessToken = file_get_contents("https://graph.facebook.com/oauth/access_token?client_id=$appID&client_secret=$appSecret&grant_type=client_credentials");

But I seem to be missing part of the core concept of how to use it. For example, when I request:

$jsonString = file_get_contents("https://graph.facebook.com/cocacola/statuses?access_token=$accessToken");

(And yeah, I'm stripping out the "access_token=" part in between the two lines, the URL is good)

I get this back:

{
   "error": {
  "message": "A user access token is required to request this resource.",
  "type": "OAuthException",
  "code": 102
  }
}

I'm a bit confused as to what I'm missing here. I know with people you need them to authorize it, but this is just a page with public statuses.

Upvotes: 1

Views: 2586

Answers (1)

Igy
Igy

Reputation: 43816

That's an app access token you're using - to make calls on behalf of a user you need them to authorise your app using the Authentication flows in the documentation

An app access token (which you get from the client_credentials call above) should give you completely public posts, but many pages are demographically restricted, or the posts themselves are targeted only at certain countries, in which case you need a user access token to retrieve them

Upvotes: 3

Related Questions