无法检索 Facebook 墙贴

发布于 2024-10-27 03:16:00 字数 1247 浏览 1 评论 0原文

使用 Facebook Graph API 和我的应用程序凭据,我能够检索有效令牌:

171372936213670|xxxxxxxxxxxxxxxxxx-650901429|x_xxxxxxxxxxxxxxx-xxxxxxxx

我用于检索墙贴的代码:

function getFbWallPosts($user, $limit=5) {
    $ci =& get_instance();
    $token = $ci->facebook->getAccessToken();
    $param = array(
        'access_token' => $token, 
        'limit' => $limit,
        );
    $posts = $ci->facebook->api("$user/feed", 'GET', $param);

    return $posts; 
}

该函数始终返回空的 json 结果:

{"data":[]}

还测试了使用 cURL 直接访问墙贴:

function fbrequest($url) {
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($ch);
    curl_close($ch);

    return $output;
}

...无济于事。

编辑:还尝试使用 file_get_contents 但它也返回空 jSON:

function fbrequest($url) {
   $output = file_get_contents($url);
   return $output;
}

尝试将请求字符串直接粘贴到我的浏览器上(没有用户登录到 Facebook):

https://graph.facebook.com/AValidFacebookUsername/feed?access_token=171372936213670|xxxxxxxxxxxxxxxxxx-650901429|x_xxxxxxxxxxxxxxx-xxxxxxxx

...成功返回包含所有帖子的 JSON 字符串

大家有什么想法吗?

Using Facebook Graph API and my app credentials I am able to retrieve a valid token:

171372936213670|xxxxxxxxxxxxxxxxxx-650901429|x_xxxxxxxxxxxxxxx-xxxxxxxx

The code I use to retrieve Wall Posts:

function getFbWallPosts($user, $limit=5) {
    $ci =& get_instance();
    $token = $ci->facebook->getAccessToken();
    $param = array(
        'access_token' => $token, 
        'limit' => $limit,
        );
    $posts = $ci->facebook->api("$user/feed", 'GET', $param);

    return $posts; 
}

The function always returns an empty jSON result:

{"data":[]}

Also tested directly accessing Wall Posts using cURL:

function fbrequest($url) {
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($ch);
    curl_close($ch);

    return $output;
}

...to no avail.

EDIT: Also tried using file_get_contents but it also returns empty jSON:

function fbrequest($url) {
   $output = file_get_contents($url);
   return $output;
}

Tried pasting the request string directly on my browser (without a user logged in to Facebook):

https://graph.facebook.com/AValidFacebookUsername/feed?access_token=171372936213670|xxxxxxxxxxxxxxxxxx-650901429|x_xxxxxxxxxxxxxxx-xxxxxxxx

...successfully returns a jSON string with all the posts

Any ideas guys?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烟花易冷人易散 2024-11-03 03:16:00

尝试...

function curl($url){
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
    $content = curl_exec($curl);
    curl_close($curl);
    return $content;
}

如果不成功,也许 Apache 编译时没有支持 SSL。

Try...

function curl($url){
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
    $content = curl_exec($curl);
    curl_close($curl);
    return $content;
}

If no luck, maybe Apache is not compiled with SSL support.

土豪 2024-11-03 03:16:00

我刚刚发现我写的代码没有任何问题。问题在于我如何解释这个过程以及最终的结果。访问 FB 上其他用户的数据有先决条件,如果是群组页面,其中之一是请求数据的用户必须是该群组的粉丝。

傻我...

I just found out that there is nothing wrong with the codes I'm writing. The problem is with how I interpreted the process and, eventually, the result. There are pre-requisites on accessing other user's data on FB and in case of group pages, one of them is that the user requesting the data MUST BE A FAN OF THAT GROUP.

Silly me...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文