简体   繁体   English

Facebook-PHP-SDK中的授权申请困难

[英]Difficulty authorizing app in Facebook-PHP-SDK

I am struggling to authorize my app in Facebook-PHP-SDK. 我正在努力在Facebook-PHP-SDK中授权我的应用程序。 The sample code I got form this link, https://developers.facebook.com/docs/php/howto/example_access_token_from_canvas , is a simple piece of code to get an access token but I cannot get my access token to access any data from Facebook through my code because I do not know how to authorize it. 我从此链接获得的示例代码https://developers.facebook.com/docs/php/howto/example_access_token_from_canvas是获取访问令牌的简单代码,但我无法获取访问令牌以从中访问任何数据Facebook通过我的代码,因为我不知道如何授权它。 One problem might be I have not finished the setup of Facebook Login as seen in the screenshot below. 问题之一可能是我尚未完成Facebook登录的设置,如下面的屏幕截图所示。 Could that be what is causing the problem? 可能是引起问题的原因吗? Code and error message below too. 下面的代码和错误消息。 Note: I have omitted my app id and secret for security reasons. 注意:出于安全原因,我已省略了我的应用ID和密码。

应用

PHP Code PHP代码

<?php
require_once(__DIR__ . '/vendor/autoload.php');
$app_id = "";
$app_secret ="";
$fb = new Facebook\Facebook([
        'app_id' => '{$app_id}',
        'app_secret' => '{$app_secret}',
        'persistent_data_handler' => 'memory',
        'default_graph_version' => 'v3.3',
]);

$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;
}

        echo 'No OAuth data could be obtained from the signed request. 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());

Error Message 错误信息

No OAuth data could be obtained from the signed request. User has not authorized your app yet.

You must login and authorize your application before to get the token, you must have a login page and the redirect page to fetch the token. 您必须先登录并授权您的应用程序才能获取令牌,您必须具有登录页面和重定向页面才能获取令牌。 check this link, because you must start by this: example login FB 检查此链接,因为必须从此开始: example login FB

Have Fun :) 玩得开心 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM