3

i am using facebook PHP sdk (v4) to fetch user information, after installing SDK, i add the code

$fb = new Facebook\Facebook([
  'app_id' => 'my app id',
  'app_secret' => 'my app secret',
  'default_graph_version' => 'v2.5',
]);

try {
  // Returns a `Facebook\FacebookResponse` object
 $access_token= //copied from my https://developers.facebook.com/tools/explorer/
  $response = $fb->get('/me?fields=id,name', '$access_token');
} catch(Facebook\Exceptions\FacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}

$user = $response->getGraphUser();

echo 'Name: ' . $user['name'];

but when i run the page it gives me this error,

Graph returned an error: Invalid appsecret_proof provided in the API argument

i am copying the app secret correctly, what could be the reason for such error and how should i fix this ?

Shahsays
  • 421
  • 1
  • 7
  • 25

5 Answers5

4

You may want to read this: https://developers.facebook.com/docs/graph-api/securing-requests

appsecret_proof is a separate parameter that is generated by using the App Secret, but it is NOT the App Secret. Information about how to generate it can be found in the docs.

andyrandy
  • 72,880
  • 8
  • 113
  • 130
4

This might help someone who lands here like me. This error also happens if the App Secret is wrong for the particular App ID

Uriahs Victor
  • 1,049
  • 14
  • 32
2

You need to select your created APP in the Facebook Graph Explorer. I was selecting my username. When I selected the app and click on "Get token" it shows me de "login panel" from my app and can generate the token.

It works for me.

Boky
  • 71
  • 4
1

Late reply but in my case was something else, so I hope it helps someone else. I see you commented:

//copied from my https://developers.facebook.com/tools/explorer/

On the top right corner of the explorer tool make sure that the selected Application is the same with the one you are using for:

$fb = new Facebook\Facebook([
  'app_id' => 'my app id',
  'app_secret' => 'my app secret',
  'default_graph_version' => 'vX.Y',
]);

If you have another Application selected and use an Access Token given for a different one (basically the default Explorer App) the hash creating the appsecret_proof will be incorrect and you will always see this error.

stevenll
  • 1,025
  • 12
  • 29
0

Or the issue could be you haven't enabled API calls to your Fb App. To enable the Api call :

1. Go to your apps section
2. Select the app that you want to use for the intergration
3. Under the App setting select advanced
4. Under security, ensure that the Allow API Access to App Settings is enebale 
   to yes
5. If need be enable any other permission that might be required.

Hope that solves the issue

stanley mbote
  • 956
  • 1
  • 7
  • 17