加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – Facebook Graph API无法访问

发布时间:2020-12-13 16:16:59 所属栏目:PHP教程 来源:网络整理
导读:我一直在使用一个Facebook应用程序,它将使用Graph API进行身份验证,明天的代码工作得很好,但现在突然间我开始收到Host无法访问的错误.我使用的代码是: $token_url = "https://graph.facebook.com/oauth/access_token?". "client_id=[client_id]". "redirect
我一直在使用一个Facebook应用程序,它将使用Graph API进行身份验证,明天的代码工作得很好,但现在突然间我开始收到Host无法访问的错误.我使用的代码是:

$token_url = "https://graph.facebook.com/oauth/access_token?".
                "client_id=[client_id]".
                "&redirect_uri=http://www.next_big_website.com".
                "&client_secret=[client_secret]".
                "&code=" . $_GET['code'].
                "&scope=manage_pages,publish_stream,publish_actions,read_mailbox,email".
                "&response_type=token";
    $response = file_get_contents($token_url);

我收到的错误是:

Warning (2): file_get_contents(https://graph.facebook.com/oauth/access_token?client_id=[client_id]&redirect_uri=http://www.next_big_website.com&client_secret=[client_secret]&code=somelong_and_ugly_code&scope=manage_pages,email&response_type=token): failed to open stream: Network is unreachable [temp.php,line 112]

请帮助我,因为我不知道是什么导致了这一点.

好吧,我进一步挖掘并找到解决方案,这是因为facebook试图强制使用IPv6,因为每当我的服务器尝试使用IPv4连接时拒绝我的请求,tracert会跟踪到Facebook API服务器的路径,然后请求被删除.

谢谢

解决方法

通过使用修复它

$url = ("https://graph.facebook.com/me/access_token?token");
    $c = curl_init();
    curl_setopt($c,CURLOPT_RETURNTRANSFER,1);
    curl_setopt($c,CURLOPT_URL,$url);
    curl_setopt($c,CURLOPT_IPRESOLVE,CURL_IPRESOLVE_V4); 
    $contents = curl_exec($c);
    $err  = curl_getinfo($c,CURLINFO_HTTP_CODE);
    curl_close($c);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读