Kannan Ramamoorthy
Kannan Ramamoorthy

Reputation: 4180

Access Token for php facebook api

I am trying to use Facebook API v2.4 to get updates of my fb and show it in my site. Having trouble with getting access token. As gone through the the page, what I need is a App Access Token.

As suggested in the documentation I tried making a GET call to /oauth/access_token. This returns me Facebook\FacebookResponse object. And using the access token in it I tried making a call to get /me

$response = $facebook->get('/me? access_token='.$accessToken);

This returns the below error,

Fatal error: Uncaught exception 'Facebook\Exceptions\FacebookAuthenticationException' with message 'An active access token must be used to query information about the current user.' in C:\xampp\htdocs\Test\Facebook\Exceptions\FacebookResponseException.php on line 125

Using the same token that I used above, I am able to get response in graph explorer. Why am I not able to use the same (App)token from my PHP? What am I missing?

Upvotes: 0

Views: 1523

Answers (1)

C3roe
C3roe

Reputation: 96306

You can not use /me in combination with an app access token – the only way the API knows who “me” is supposed to be, is via the access token; and therefor it works with user or page access tokens only. Use the id of the user profile or page(?) instead.

And getting a user or page access token requires user interaction. You can extend their validity period though, see https://developers.facebook.com/docs/facebook-login/access-tokens#extending

Upvotes: 1

Related Questions