显示Facebook喜欢没有按钮

时间:2012-07-24 17:13:55

标签: facebook facebook-like

我正在尝试显示我在Facebook上的喜欢数量,但没有他们丑陋的按钮。有没有办法在没有任何图像的情况下获得喜欢的数量,以便我可以将css应用于数字并将其显示在我的主网页上?

开发人员页面似乎没有任何帮助,我可以找到。

谢谢!

2 个答案:

答案 0 :(得分:1)

向图API发出http请求:

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令牌并将其传递给Graph API

如果您需要更多信息,请在开发人员帮助中查看OAuth和Open Graph API。 (https://developers.facebook.com/docs/opengraph/tutorial/)

答案 1 :(得分:0)

$pageContent = file_get_contents('http://graph.facebook.com/YOURPAGENAMEHERE');
$parsedJson  = json_decode($pageContent);
$likes = $parsedJson->likes;
echo $likes;

我自己跑这个。请记住,您使用cronjob执行此操作并将其存储在数据库中,因为它非常慢。