从 Facebook Graph API 获取 404 错误 [英] Getting 404 Error from Facebook Graph API

查看:30
本文介绍了从 Facebook Graph API 获取 404 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我收到了这个错误,我不知道为什么.当我在服务器上运行它时我收到一个 404 错误,像这样一个简单的请求.

So I am getting this error and I have no clue why. 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);

错误是:

function.file-get-contents: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found

但是,我可以同时将我与 file_get_contents 一起使用的 URL 直接粘贴到浏览器中,然后它就会出现.所以看起来 Facebook 正在阻止我的服务器.

However, I can paste the URL that I am using with file_get_contents directly in the browser at the same time and it comes up. So it seems as if Facebook is blocking my server.

它也有一半的时间.

有什么想法吗?

推荐答案

尝试 cURL,不知道为什么 file_get_contents 不可靠,但我过去也遇到过同样的问题.我使用这个 geturl 函数来卷曲 URL 并将参数作为 PHP 数组传入

Try cURL, not sure why file_get_contents is unreliable but I have seen the same issue in the past. I use this geturl function to cURL a URL and pass the parameters in as a PHP array

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;
}

然后可以这样调用

$url = 'https://www.graph.facebook.com/me';
$params = array('access_token' => '*********************');
$graph_ret = geturl($url, $params);

这篇关于从 Facebook Graph API 获取 404 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆