简体   繁体   中英

Difficulty authorizing app in Facebook-PHP-SDK

I am struggling to authorize my app in 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. One problem might be I have not finished the setup of Facebook Login as seen in the screenshot below. 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.

应用

PHP Code

<?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

Have Fun :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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