Reputation: 1021
I'm trying to display the number of likes I have on Facebook but without their ugly button. Is there a way to just get the number of likes without any images so that I can apply css to just the number and display it on my main webpage?
There Developer page doesn't seem to be any help that I can find.
Thanks!
Upvotes: 0
Views: 238
Reputation: 331
$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.
Upvotes: 0
Reputation: 5225
Make a http request to the graph API:
https://graph.facebook.com/{your-page-name-or-id}
It will return a json object containing information of this page. You can test it on your browser. An example:
https://graph.facebook.com/cocacola
returns:
{
"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
}
It also works for profiles (the information returned is different), apps, and any facebook object! This only returns public information. If you want to retrieve private information (maybe pictures or posts) you need to get an OAuth token and pass it to the Graph API
If you need more info, check OAuth and Open Graph API on the developers help. (https://developers.facebook.com/docs/opengraph/tutorial/)
Upvotes: 1