我正在关注Facebook的SDK,但我收到以下错误:
没有设置网址。
以下是代码:
<?php
require_once __DIR__ . '/src/autoload.php';
session_start();
$fb = new Facebook\Facebook([
'app_id' => '',
'app_secret' => '',
'default_graph_version' => 'v2.2',
]);
// Use one of the helper classes to get a Facebook\Authentication\AccessToken entity.
$helper = $fb->getRedirectLoginHelper();
//$helper = $fb->getJavaScriptHelper();
//$helper = $fb->getCanvasHelper();
//$helper = $fb->getPageTabHelper();
try {
// Get the Facebook\GraphNodes\GraphUser object for the current user.
// If you provided a 'default_access_token', the '{access-token}' is optional.
$response = $fb->get('/me', '{access-token}');
} 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;
}
$me = $response->getGraphUser();
echo 'Logged in as ' . $me->getName();
?>
为什么我收到此错误?
答案 0 :(得分:0)
也许您没有重定向到正确的登录网址
$fb = new Facebook\Facebook([
'app_id' => '',
'app_secret' => '',
'default_graph_version' => 'v2.2',
]);
$helper = $fb->getRedirectLoginHelper();
$permissions = ['email', 'public_profile'];
$callback = 'http://yoursite.com/callbackscript.php < your file';
$loginUrl = $helper->getLoginUrl($callback, $permissions);
<a href="<?= $loginUrl; ?>">Login with Facebook!</a>
答案 1 :(得分:0)
请确保在php.ini
中启用php_curl.dll
扩展名