上周,我在CODEIGNITER 3上通过composer安装了facebook SDK,它可以正常工作并返回名称电子邮件和令牌,直到今天,当我尝试登录时页面加载1分钟,然后出现空白页面,并出现以下错误:
>空错误 Facebook SDK返回错误:
我在控制器中使用2个操作进行登录:
function fblogin(){
$fb = new Facebook\Facebook([
'app_id' => 'my app id ',
'app_secret' => 'my app secret',
'default_graph_version' => 'v3.2',
]);
$helper = $fb->getRedirectLoginHelper();
$permissions = ['email'];
// For more permissions like user location etc you need to send your application for review
$loginUrl = $helper->getLoginUrl('https://www.example.com/en/fbcallback', $permissions);
header("location: ".$loginUrl);
}
此应返回令牌信息的位置:
function fbcallback(){
$fb = new Facebook\Facebook([
'app_id' => 'myid',
'app_secret' => 'myscretapp',
'default_graph_version' => 'v3.2',
]);
$helper = $fb->getRedirectLoginHelper();
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;
}
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?fields=id,name,email,first_name,last_name',$accessToken);
// print_r($response);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'ERROR: Graph ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'ERROR: validation fails ' . $e->getMessage();
exit;
}
// User Information Retrival begins................................................
$me = $response->getGraphUser();
echo "First Name: ".$me->getProperty('first_name')."<br>";
echo "Last Name: ".$me->getProperty('last_name')."<br>";
echo "Email: ".$me->getProperty('email')."<br>";
echo "Facebook ID: <a href='https://www.facebook.com/".$me->getProperty('id')."' target='_blank'>".$me->getProperty('id')."</a>"."<br>";
$profileid = $me->getProperty('id');
echo "</br><img src='//graph.facebook.com/$profileid/picture?type=large'> ";
echo "</br></br>Access Token : </br>".$accessToken;
}
2年前问了同样的问题,但没有答案: link
答案 0 :(得分:0)
我的问题出在服务器端:
此功能允许您指定某些IP或IP范围,您可以将其打开传出连接。
只需转到服务器,然后检查它是否阻止传出连接即可。... 我将其添加到白名单中并正常工作! ...希望可以节省您的时间。