Very new to PHP and downloaded Facebook-PHP-SDK and I am trying to run a simple code I found online but I keep getting an error. I have done lots of research on the problem, looked at similar questions on here and so for but have not been able to find anything that helps. It looks like I still need to authorize the app I created in Facebook Developers, but I cannot figure out how to do that.
<?php
require_once(__DIR__ . '/vendor/autoload.php');
$fb = new Facebook\Facebook([
'app_id' => '{}',
'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;
}
if (! isset($accessToken)) {
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 are not supplying the SDK with the required app_id
and app_secret
so it can't do anything. That's why it gives you an OAUTH error. ( fb-docs )
$fb = new Facebook\Facebook([
'app_id' => '{}', // Here
'app_secret' => '{}', // Here
'persistent_data_handler' => 'memory',
'default_graph_version' => 'v3.3',
]);
You need to get that data from your facebook app configuration dashboard . And plug into this object.
example:
$app_id = "1234";
$app_secret = "foobar";
$fb = new Facebook\Facebook([
'app_id' => '{$app_id}',
'app_secret' => '{$app_secret}',
'default_graph_version' => 'v3.2',
]);
Apps are all registered and managed at https://developers.facebook.com/ . Have you checked your settings there?
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.