无法检索 Facebook 墙贴
使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试...
如果不成功,也许 Apache 编译时没有支持 SSL。
Try...
If no luck, maybe Apache is not compiled with SSL support.
我刚刚发现我写的代码没有任何问题。问题在于我如何解释这个过程以及最终的结果。访问 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...