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

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

问题描述

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

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 直接在浏览器中同时出现。所以似乎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函数来cURL一个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天全站免登陆