如何在FB页面上计算喜欢人数? [英] How to count likes on FB page?

查看:157
本文介绍了如何在FB页面上计算喜欢人数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须做一个非常简单的操作,但是我的编程技能还不够.我必须在Facebook页面上点赞,并在我的网站上打印该号码.我有两个脚本可以很好地处理普通网站,但是它们不想显示页面的喜欢次数.

I have to do a very simple operation but my programming skills are not enough. I have to count likes in Facebook page and print that number on my web-site. I have two scripts that do the job well for ordinary web-sites, but they don't want to show the number of likes for the page.

<?php
$source_url = "http://www.facebook.com/";  //This could be anything URL source  including stripslashes($_POST['url'])
$url = "http://api.facebook.com/restserver.php?method=links.getStats&urls=".urlencode($source_url);
$likes =  $xml->link_stat->like_count;
$comments = $xml->link_stat->comment_count;
$total = $xml->link_stat->total_count;
$max = max($shares,$likes,$comments);
echo $likes;
?>

<?php
$fql  = "SELECT url, normalized_url, share_count, like_count, comment_count, ";
$fql .= "total_count, commentsbox_count, comments_fbid, click_count FROM ";
$fql .= "link_stat WHERE url = 'http://www.apple.com/'";
$apifql="https://api.facebook.com/method/fql.query?format=json&query=".urlencode($fql);
$json=file_get_contents($apifql);
print_r( json_decode($json));
?>

这两个脚本都可用于普通网站,但无法获取fb页面喜欢的号码.可能我应该以其他格式输入链接吗?

Both scripts work for ordinary web-sites but cant fetch fb page likes number. May be I should enter the link in another format or something?

我可以使用类似 http://graph.facebook.com/?ids的图形来获取所需数据= AutoSpecCenter ,只需输入这样的页面名称即可.但是我不知道如何处理这些数据.

I can get required data using graph like this http://graph.facebook.com/?ids=AutoSpecCenter , just by entering page name like that. But I don't know how to manipulate with this data.

推荐答案

正如您在问题中所写的那样,您可以通过Facebook的Graph API查询此类信息.这个简短的示例将获取可口可乐页面的信息,解码JSON并输出喜欢页面$data->likes的人数.

As you already wrote in your question, you can query such information through Facebooks' Graph API. This short example will get the information of the Coca-Cola page, decode the JSON and outputs the number of people that like the page $data->likes.

<?php 
$ch = curl_init("https://graph.facebook.com/CocaCola?access_token=<Access Token>");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$raw = curl_exec($ch);
curl_close($ch);

$data = json_decode($raw);
echo $data->likes . " people like Coca-Cola";
?>

如果您需要执行的任务不仅仅是获取页面喜欢的内容,请考虑使用 Facebook SDK 作为 cpilko .

If you need to perform more tasks than just getting the likes of a page, consider using the Facebook SDK as cpilko suggested.

这篇关于如何在FB页面上计算喜欢人数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆