douhuigan8063 2015-02-03 18:13
浏览 44

Facebook PHP SDK提供了很多例外

These are the exceptions

exception 'Facebook\FacebookSDKException' with message 'Failed to connect to 2a03:2880:20:4f06:face:b00c:0:1: Network is unreachable' in /home/handsrhf/public_html/www.bhartibattery.com/inc/facebook/HttpClients/FacebookCurlHttpClient.php:150 Stack trace: #0 /home/handsrhf/public_html/www.bhartibattery.com/inc/facebook/FacebookRequest.php(248): Facebook\HttpClients\FacebookCurlHttpClient->send('https://graph.f...', 'GET', Array) #1 /home/handsrhf/public_html/www.bhartibattery.com/inc/facebook/FacebookRedirectLoginHelper.php(185): Facebook\FacebookRequest->execute() #2 /home/handsrhf/public_html/www.bhartibattery.com/index.php(45): Facebook\FacebookRedirectLoginHelper->getSessionFromRedirect() #3 {main}

This is the code

$appId = '541501275992239';
$appSecret = 'a6b15bbdd2f6b3a7a5a8893d7aca3f06';
$redirectUrl = 'http://www.bhartibattery.com';

FacebookSession::setDefaultApplication($appId, $appSecret);

$helper = new FacebookRedirectLoginHelper($redirectUrl);

try{
    $session = $helper->getSessionFromRedirect();
}
catch(FacebookRequestException $ex) {
    echo 'Facebook error';
}
catch(Exception $e) {
    echo 'Something went wrong:' . $e ;
}

$loginUrl = $helper->getLoginUrl();

if(isset($session)) {
    $request = new FacebookRequest($session, 'GET', '/me');
    $response = $request->execute();
    $graphObject = $response->getGraphObject(GraphUser::classname());

    $name = $graphObject->getName();
    $id = $graphObject->getId();
    $img = 'https://graph.facebook.com/' . $id . '/picture?width=500';

    echo 'Hi' . $name . '<br>';
    echo 'Photo: <img src=' .$img . '><br>';
}
else{
    echo '<a href="' . $loginUrl . '">Login with Facebook</a>';
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料