使用php sdk在Facebook中获取访问令牌时出错 [英] Error to get the access token in facebook using php sdk
问题描述
我正在使用的代码:
$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());
输出: 这仅表明:无法从已签名的请求中获取OAuth数据.用户尚未授权您的应用
Output: This only shows that: No OAuth data could be obtained from the signed request. A user has not authorized your app yet
我正在使用页面的app_id and app_secret
.
推荐答案
您正在使用的示例(...)涵盖了从应用画布(...)的上下文中获取访问令牌和签名请求的过程" . https://developers.facebook.com/docs/php/howto/example_access_token_from_canvas
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
应用画布的上下文意味着您的应用已嵌入Facebook(iframe)中. https://stackoverflow.com/a/41669757/2911960
Context of an app canvas means that your app is embeded on Facebook (iframe). https://stackoverflow.com/a/41669757/2911960
我假设您要在您的网站上使用该API.然后,您正在寻找: https://developers.facebook.com/docs/php/howto/example_facebook_login
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
这篇关于使用php sdk在Facebook中获取访问令牌时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!