我試圖顯示我在Facebook上有喜歡的數量,但沒有他們醜陋的按鈕。有沒有辦法只獲得沒有任何圖像的喜歡數量,以便我可以將CSS應用於數字並將其顯示在我的主網頁上?顯示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