Jef*_*ter 3 facebook http-status-code-404 facebook-graph-api
所以我收到这个错误,我不知道为什么. When I run it on the server it's on,I get a 404 error with a simple request like this.
$json = file_get_contents('https://graph.facebook.com/me?access_token='.LONGSTRING);
Run Code Online (Sandbox Code Playgroud)
错误是:
function.file-get-contents: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
Run Code Online (Sandbox Code Playgroud)
但是,我可以同时将我正在使用的URL粘贴到file_get_contents浏览器中,然后出现.所以好像Facebook正在阻止我的服务器.
它也有一半的时间.
有任何想法吗?
尝试cURL,不知道为什么file_get_contents不可靠但我过去看过同样的问题.我使用这个geturl函数来cURL一个URL并将参数作为PHP数组传递
function geturl($url, $params) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params, null, '&'));
$ret = curl_exec($ch);
curl_close($ch);
return $ret;
}
Run Code Online (Sandbox Code Playgroud)
然后可以这样调用
$url = 'https://www.graph.facebook.com/me';
$params = array('access_token' => '*********************');
$graph_ret = geturl($url, $params);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2652 次 |
| 最近记录: |