file_get_contents通过facebook graph api返回403 Forbidden

时间:2015-09-02 08:26:14

标签: facebook facebook-graph-api

我使用以下代码获取特定网址的Facebook评论数量。

function get_facebook_comments_number() {
    $filecontent = file_get_contents('http://graph.facebook.com/?ids=' . $url);
    $json = json_decode($filecontent);
    $count = $json->$url->comments;
    if ($count == 0 || !isset($count)) {
        $count = 0;
    }
    return $count;
}

有时它会起作用,但突然间它会停止处理以下错误:

Failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden

在服务器端,一切都应该正常工作。如果我使用不同的URL(例如http://www.google.com),它可以完美运行。所以我似乎达到了facebook图API的一些限制。如果我在浏览器中输入相同的URL,则不会返回错误。

有谁知道如何解决这个问题?我是否必须传递某种身份验证码?

0 个答案:

没有答案
相关问题