如何使用新的 facebook API 检索 like_count 的数量?
我正在为我的网站使用“赞”按钮,使用 iframe 版本从 facebook 页面获取它。我只想在这个数字大于 50 时显示喜欢我的网站的人数。我想我可以使用 fql.query 来获取 like_count ,如果这个数字大于 50 则显示它。我不想在开发者页面中创建 Facebook 应用程序,因此我没有应用程序 ID 等。 我所做的是:
$data = array(
'method' => 'fql.query',
'query' => 'select like_count from link_stat where url="http://www.mysite.com',
'callback' => ''
);
但我不知道如何将结果存储在 PHP 变量中,如果最后我只能在我想要的时候显示它们。
我已经搜索了很多,但还没有找到任何东西,所以如果有人可以帮助我,我将非常感激。
I am using a like button for my web site, got it from the facebook page using the iframe version. I want to show the number of people like my site only when this number is bigger that 50. I was thinking that I could use an fql.query for getting the like_count and if this is bigger that 50 then show it. I don't want to create a Facebook App in the developers page so I don't have an App id etc.
What I have done is:
$data = array(
'method' => 'fql.query',
'query' => 'select like_count from link_stat where url="http://www.mysite.com',
'callback' => ''
);
But I do not know how to store the results in a PHP variable and if at the end I can display them only when I want to.
I have searched a lot about it and not find something yet so I would appreciate a lot if someone could help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以向 http://graph.facebook.com/http 发出请求: //www.mysite.com/ 在 Javascript 中,它将返回一个包含分享数量和评论数量的 JSON 对象,因此:
该分享数量应该与您在“点赞”按钮中获得的数量相匹配。
You can do a request to http://graph.facebook.com/http://www.mysite.com/ in Javascript, and it will return a JSON object with the number of shares and comments thus:
That shares number should match the number you will get in the like button.
只需调用没有任何 access_token 的 graph-api,例如
https://api.facebook.com/method/fql.query?query =SELECT+url%2C+normalized_url%2C+share_count%2C+like_count%2C+comment_count%2C+total_count%2C+commentsbox_count%2C+comments_fbid%2C+click_count+FROM+link_stat+WHERE+url%3D"facebook.com ”
Just call the graph-api without any access_token, e.g.
https://api.facebook.com/method/fql.query?query=SELECT+url%2C+normalized_url%2C+share_count%2C+like_count%2C+comment_count%2C+total_count%2C+commentsbox_count%2C+comments_fbid%2C+click_count+FROM+link_stat+WHERE+url%3D"facebook.com"
其实我不知道你是否需要注册一个App。我知道您可以在没有 App ID 的情况下使用 Graph API 执行一些操作(尽管显然,如果它是一个封闭的组或事件,我猜您需要能够为此获取 OAuth access_token)。我根本没有使用过 FQL,但我很确定您不需要 App ID 来执行某些操作。
为了回答OP,此链接: http://developers.facebook.com/docs/ Reference/fql/link_stat 使用他们似乎自始至终都在使用的 $facebook 对象。在 github 上查看此代码:https://github。 com/facebook/php-sdk/blob/master/examples/example.php
这可能会有所帮助。
Actually, I don't know if you do need to register an App. I know you can do some things using the Graph API without an App ID (although obviously if it's a closed group or event I'm guessing you'd need to be able to get an OAuth access_token for that). I haven't used FQL at all, but I'm pretty sure that you don't need an App ID to do some things.
In answer to the OP, this link: http://developers.facebook.com/docs/reference/fql/link_stat uses the $facebook object that they seem to use throughout. Take a look at this code on github: https://github.com/facebook/php-sdk/blob/master/examples/example.php
That might help.