【问题标题】:Warning: file_get_contents(https://graph.facebook.com/me?access_token=)警告:file_get_contents(https://graph.facebook.com/me?access_token=)
【发布时间】:2011-09-04 19:06:19
【问题描述】:
Warning: file_get_contents(https://graph.facebook.com/me?access_token=) [function.file-                get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request in /var/www/dsg/signed_request.php on line 25

我已经在我的 php.ini 中检查并设置了 allow_url_fopen 并确保在我运行 phpinfo(); 时 allow_url_fopen 是打开的。我仍然收到上面列出的错误。有谁知道这是否可以以某种方式工作?也许有一些转换为替代品?

【问题讨论】:

    标签: facebook https file-get-contents


    【解决方案1】:

    您可以使用 curl,它实际上应该用于网络请求,而不是 file_get_contents。我不知道为什么 Facebook 在示例中开始使用该功能。 Curl 具有错误处理功能,并且会根据需要跟踪重定向,因此您可以准确了解发生了什么。

    【讨论】:

    • 我现在正在使用 curl。现在我收到一个错误。必须使用活动访问令牌来查询有关当前用户的信息。
    • 那么你们沟通得很好。您需要启动会话以获取要包含在 URL 中的访问令牌。
    【解决方案2】:

    你可以像这样创建自己的单行函数

    function viacurl($location){
        $ch = curl_init();
    
        curl_setopt($ch, CURLOPT_URL, $location);
        curl_setopt($ch, CURLOPT_HEADER, false);
    
        $out=curl_exec($ch);
    
        curl_close($ch);
    
        return rtrim($out,1);
    }
    

    并像这样使用它:

    $response = viacurl($url);
    

    【讨论】:

      猜你喜欢
      • 2011-06-10
      • 2012-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-24
      • 1970-01-01
      • 2017-07-17
      • 1970-01-01
      相关资源
      最近更新 更多