【问题标题】:Facebook Graph API UnreachableFacebook Graph API 无法访问
【发布时间】:2012-06-24 08:17:02
【问题描述】:

我一直在开发一个将使用 Graph API 进行身份验证的 facebook 应用程序,该代码明天工作得很好,但现在我突然开始收到 Host is unreachable 错误。我使用的代码是:

$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);

我收到的错误是:

警告 (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, publish_stream,publish_actions,read_mailbox,email&response_type=token):无法打开流:网络无法访问 [temp.php,第 112 行]

请帮我解决这个问题,因为我不知道是什么原因造成的。

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

谢谢

【问题讨论】:

  • 您的 php.ini 中是否为 file_get_content 打开了 https 流?另外,你想用这个电话做什么?
  • 如何打开这些?我正在尝试获取用户的访问令牌。谢谢
  • 用户是否对您的应用进行了身份验证?
  • 这是您这边的网络问题,请检查您的网络设置,特别是检查您的 IPV4 和 IPV6 接口是否都已配置
  • 这几乎肯定不是代码问题,这是您的代码无法访问 facebook 的服务器,这是您的服务器配置、防火墙、主机、ISP 或其他问题网络

标签: php facebook facebook-graph-api file-get-contents


【解决方案1】:

通过使用修复它

 $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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-04
    • 1970-01-01
    • 2013-12-20
    • 1970-01-01
    • 1970-01-01
    • 2016-02-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多