获取 Facebook 图形 API JSON 值
我有一个简单的 PHP 代码,它通过 JSON 获取 Facebook 图形 API 的值(某个粉丝页面的点赞总数)。它对于绝大多数粉丝页面都工作得很好,但对于 3 个(我跟踪的 17 个粉丝页面中的)它根本无法读取和打印该值。
我不明白问题出在哪里,因为我想要获取的数据是公开可用的,并且相同的代码应用于所有页面。
下面是打印 ID 为 214014840762 的粉丝页面的正确值的代码:
<?php
$currsiteurl = 'http://graph.facebook.com/214014840762';
$graph = json_decode(file_get_contents($currsiteurl));
$currnofans = $graph->likes;
echo "Number of likes: ".$currnofans; // prints out 107936
?>
但是,如果我只是将 ID 更改为 160788560626000 或 167134649991034,则相同的代码将不再工作,并且不会打印任何内容。
提前致谢!
I have a simple PHP code that fetches Facebook graph API's value (total number of likes of a certain fanpage) via JSON. It works perfectly fine for the vast majority of fan pages but for 3 (out of 17 fan pages that I track) it simply can't read and print that value.
I don't understand where's the problem since the data I want to fetch is publicly available and the same code is applied for all pages.
Here's the code that prints correct value for a fan page with ID 214014840762:
<?php
$currsiteurl = 'http://graph.facebook.com/214014840762';
$graph = json_decode(file_get_contents($currsiteurl));
$currnofans = $graph->likes;
echo "Number of likes: ".$currnofans; // prints out 107936
?>
But if I simply change the ID to 160788560626000 or 167134649991034 the same code doesn't work anymore and it doesn't print anything.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道这些页面是什么,也不知道它们在 Facebook 上的 URL 是什么,所以我无法验证这一点,但是,您的页面可能未发布(可能不太可能),或者(可能更有可能)已过时受限制的。 Facebook 图表不允许您访问受年龄限制的页面信息。不幸的是,如果您传递 Facebook 应用程序访问令牌,甚至是 18 岁以上用户的访问令牌,情况也是如此。这非常愚蠢,并且 bugs.developers.facebook 上至少有 5 个错误报告。 com 为它。
2011 年 6 月 13 日更新
)或
最近,Facebook 进行了更新,要求您使用有效的用户访问令牌来提取有关页面的信息。在我看来,这是一个可怕的变化,但事实就是如此。如果没有有效的用户访问令牌,您将从每个不是基本信息的端点(root、http://graph .facebook.com/
照片
或相册
端点。因此,如果您请求任何其他端点(
posts
、feed
、videos
、statuses
等)您需要确保提供有效的用户访问令牌来访问它们。I don't know what these pages are or what their URLs on Facebook are, so I can't verify this but, it's possible that your page is either not published (probably not that likely), or (probably more likely) is age restricted. The Facebook graph doesn't let you access a page's information if it is restricted by age. Unfortunately, this is even true if you pass a Facebook application access token, or even an access token for a user who is over 18. It's pretty stupid, and there have got to be at least 5 bug reports on bugs.developers.facebook.com for it.
Update 6/13/2011
Recently, Facebook made an update that requires you to use a valid user access token to pull information about a page. This is a horrendous change, imo, but it is what it is. Without a valid user access token, you will get a
false
orerror
response from every endpoint that isn't the basic info (root,http://graph.facebook.com/<page_id>
) orphotos
, oralbums
endpoints.So, if you're requested any of the other endpoints (
posts
,feed
,videos
,statuses
, etc) you'll need to make sure you provide a valid user access token to access them.如果我是对的那么结果是一个数组而不是一个类
所以尝试类似 $graph["likes"]
If I'm right then is the result an array and not a class
so try something like $graph["likes"]