显示Facebook喜欢没有按钮
问题描述:
我试图显示我在Facebook上有喜欢的数量,但没有他们丑陋的按钮。有没有办法只获得没有任何图像的喜欢数量,以便我可以将CSS应用于数字并将其显示在我的主网页上?显示Facebook喜欢没有按钮
那里开发者页面似乎没有任何帮助,我可以找到。
谢谢!
答
做一个HTTP请求到图形API:
https://graph.facebook.com/ {您的页面名称,或-ID}
它会返回一个包含此页面的信息的JSON对象。您可以在浏览器上测试它。举个例子:
https://graph.facebook.com/cocacola
回报:
{
"id": "40796308305",
"name": "Coca-Cola",
"picture": "http://profile.ak.fbcdn.net/hprofile-ak-snc4/174560_40796308305_2093137831_s.jpg",
"link": "https://www.facebook.com/coca-cola",
"likes": 45669549,
"cover": {
"cover_id": "10151829640053306",
"source": "http://a8.sphotos.ak.fbcdn.net/hphotos-ak-ash3/s720x720/529413_10151829640053306_446360541_n.jpg",
"offset_y": 0
},
"category": "Food/beverages",
"is_published": true,
"website": "http://www.coca-cola.com",
"username": "coca-cola",
"founded": "1886",
"description": "Created in 1886 in Atlanta, Georgia, by Dr. John S. Pemberton, Coca-Cola was first offered as a fountain beverage at Jacob's Pharmacy by mixing Coca-Cola syrup with carbonated water. \n\nCoca-Cola was patented in 1887, registered as a trademark in 1893 and by 1895 it was being sold in every state and territory in the United States. In 1899, The Coca-Cola Company began franchised bottling operations in the United States. \n\nCoca-Cola might owe its origins to the United States, but its popularity has made it truly universal. Today, you can find Coca-Cola in virtually every part of the world.",
"about": "The Coca-Cola Facebook Page is a collection of your stories showing how people from around the world have helped make Coke into what it is today.",
"checkins": 106,
"talking_about_count": 671246
}
它也适用于配置文件(返回的信息是不同的),应用程序和任何Facebook的对象! 这只会返回公开信息。如果您想要检索隐私信息(可能是图片或帖子),您需要获得OAuth令牌并将其传递给图形API
如果您需要更多信息,请查看开发人员帮助上的OAuth和Open Graph API。 (https://developers.facebook.com/docs/opengraph/tutorial/)
答
$pageContent = file_get_contents('http://graph.facebook.com/YOURPAGENAMEHERE');
$parsedJson = json_decode($pageContent);
$likes = $parsedJson->likes;
echo $likes;
我有这个自己运行。请记住,您使用cronjob执行此操作,并将其存储在数据库中,因为它非常慢。
太棒了。我的问题是关于JSON。我如何告诉我的网站获取这些信息?我知道JSON,但我只是在学习。有小费吗? – Devin 2012-07-24 18:41:45
JSON是Javascript对象的文本表示。基本上有两种方法可以从浏览器使用JavaScript或从服务器访问此信息。 Javascript有一个重要的限制,它只允许从你自己的域访问资源。你可以:1)使用JS facebook api(起初稍微复杂)或者2)在你的服务器上发布一个PHP脚本,它像一个获取这些数据的代理,并使用jQuery.ajax(“yourserver.com/proxy.php ?url = ...“,函数(data){...对数据做些什么...}); – Xocoatzin 2012-07-24 18:48:58