我正在尝试显示我在 Facebook 上的点赞数,但没有丑陋的按钮。有没有办法在没有任何图像的情况下获得喜欢的数量,以便我可以将 css 应用于数量并将其显示在我的主网页上?
那里的开发人员页面似乎没有我能找到的任何帮助。
谢谢!
我正在尝试显示我在 Facebook 上的点赞数,但没有丑陋的按钮。有没有办法在没有任何图像的情况下获得喜欢的数量,以便我可以将 css 应用于数量并将其显示在我的主网页上?
那里的开发人员页面似乎没有我能找到的任何帮助。
谢谢!
向图形 API 发出 http 请求:
https://graph.facebook.com/ {your-page-name-or-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/)
$pageContent = file_get_contents('http://graph.facebook.com/YOURPAGENAMEHERE');
$parsedJson = json_decode($pageContent);
$likes = $parsedJson->likes;
echo $likes;
I have this one running myself. Keep in mind that you do this with a cronjob and store it in your database because it is quite slow.