问题
The code that I'm using :
$fb = new Facebook\Facebook([
'app_id' => '{app-id}',
'app_secret' => '{app-secret}',
'default_graph_version' => 'v2.6',
]);
$helper = $fb->getCanvasHelper();
try {
$accessToken = $helper->getAccessToken();
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
if (! isset($accessToken)) {
echo 'No OAuth data could be obtained from the signed request. A user has not authorized your app yet.';
exit;
}
// Logged in
echo '<h3>Signed Request</h3>';
var_dump($helper->getSignedRequest());
echo '<h3>Access Token</h3>';
var_dump($accessToken->getValue());
Output: This only shows that: No OAuth data could be obtained from the signed request. A user has not authorized your app yet
I am using my page's app_id and app_secret
.
回答1:
The example you are using "(...) covers obtaining an access token and signed request FROM WITHIN THE CONTEXT OF AN APP CANVAS (...)". https://developers.facebook.com/docs/php/howto/example_access_token_from_canvas
Context of an app canvas means that your app is embeded on Facebook (iframe). https://stackoverflow.com/a/41669757/2911960
I assume you want to use the API on your website. Then you are looking for this: https://developers.facebook.com/docs/php/howto/example_facebook_login
来源:https://stackoverflow.com/questions/40882664/error-to-get-the-access-token-in-facebook-using-php-sdk