Display Facebook likes without button - facebook

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!

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/)

$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.

Related

Facebook rankings and kpi for specific pages

I would like to make an application or even a page in my localhost to do what fanpage karma facebook rankings does.
I don't want the facebook insights because I want to have kpi,graphs/charts,rankings and/or insights for the pages i want, just like the fanpagekarma does.
Most of this information can be obtained via
graph.facebook.com/PAGE_ID which will give for example graph.facebook.com/cocacola
{
"id": "40796308305",
"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.",
"app_id": "0",
"can_post": false,
"category": "Food/beverages",
"checkins": 146,
"cover": {
"cover_id": "10152297032458306",
"source": "http://sphotos-f.ak.fbcdn.net/hphotos-ak-prn1/s720x720/625442_10152297032458306_574021701_n.jpg",
"offset_y": 0,
"offset_x": 0
},
"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.\n\nCoca-Cola Page House Rules: http://CokeURL.com/q28a",
"founded": "1886",
"has_added_app": false,
"is_community_page": false,
"is_published": true,
"likes": 64355037,
"link": "https://www.facebook.com/coca-cola",
"name": "Coca-Cola",
"talking_about_count": 1485039,
"username": "coca-cola",
"website": "http://www.coca-cola.com",
"were_here_count": 0
}
In the KPI Overview this takes care of
Fans
Talking about
Then when a user logins into fanpagekarma, the call to graph.facebook.com/page_id/posts can be used to get
Posts per day
Response rate
Engagement
Post Interaction
Post History
The rest of the detailed analytics is just some number crunching on the data from /page_id/posts

Can I aggregate Facebook Likes, Tweets, and Google Pluses?

I'm building a voting application on my new website, cabinethardware.org. I'd like the voting to be done in such a way that when someone votes for a project (to receive a $1000 rebuilding grant) that they are encouraged to plug the project via social networks. My programmer has had difficulty with the application, and it occurred to me that one way of doing it is to just put like, tweet and G+ buttons on the site and add them together. So if a project gets 24 likes, 12 tweets, and 18 G+, it would have 64 votes. It doesn't bother me if someone votes on all three engines.
Before a project is eligible for a grant, it must receive 100 votes. My question is, is there a way that I can aggregate the likes, tweets, and G+ so that I can see on the backend how many votes each project has, without going to each project and adding them up by hand? Also, I'd like to display to customers the combined total.
Does anyone know of a way to combine the count of these three?
For Google+, you would only need to perform one API call to the Google+ APIs that would be searching the Google+ public data. Searching the Google+ public data is demonstrated in the API explorer.
The post response contains information about reshares and +1s:
"verb": "post",
"object": {
"objectType": "note",
"content": "Setting up a server-side flow project that accesses Google+ data using the .NET stack can be a little tricky, I walk you through it in this blog post.",
"url": "https://plus.google.com/109716647623830091721/posts/g8LjdGAXdDc",
"replies": {
"totalItems": 0,
"selfLink": "https://www.googleapis.com/plus/v1/activities/z125srm50lf1slxrd04cfftatqyoglnoqio/comments"
},
"plusoners": {
"totalItems": 6,
"selfLink": "https://www.googleapis.com/plus/v1/activities/z125srm50lf1slxrd04cfftatqyoglnoqio/people/plusoners"
},
"resharers": {
"totalItems": 0,
"selfLink": "https://www.googleapis.com/plus/v1/activities/z125srm50lf1slxrd04cfftatqyoglnoqio/people/resharers"
},
For Facebook, you can use the Pages API to count likes for your page, you can experiment with this in their API explorer.
The following data shows their response data:
{
"about": "Build and distribute amazing social apps on Facebook. https://developers.facebook.com/ ",
"company_overview": "Facebook Platform enables anyone to build social apps on Facebook, mobile, and the web.\n\n",
"is_published": true,
"talking_about_count": 39241,
"username": "FacebookDevelopers",
"website": "http://developers.facebook.com",
"were_here_count": 0,
"category": "Product/service",
"id": "19292868552",
"name": "Facebook Developers",
"link": "https://www.facebook.com/FacebookDevelopers",
"likes": 952596,
"cover": {
"cover_id": "10151121467948553",
"source": "https://fbcdn-sphotos-f-a.akamaihd.net/hphotos-ak-ash4/s720x720/299374_10151121467948553_45631061_n.png",
"offset_y": 0
}
}
Likes are just a member in the response data.
For twitter, you can query for mentions of a user with their search API and passing a search string for the user as #user. A count of the objects within results is going to be your mention count. The response data is a little too much to paste in here but here's an example query using their API.

How to correctly redirect to the facebook page tab URL after authorization

I have changed the way my facebook page tab app asks for permissions.
I was using the javascript approach with FB Dialog and now I am using the redirect approach (in which the user is redirected to a FB page where the permissions are asked and then is redirected back to the facebook page tab).
The reason of the change is that I believe this approach will present
less bugs and issues than using the javascript dialogs.
When using the redirect approach, I need to specify the URL that the user will be redirected after providing permissions. I would like that this url was the url of the facebook page tab with the app installed.
When building the url of redirect, I know the current page_id and my app_id. With these info, I need to build the facebook page tab url, which should look like this:
https://www.facebook.com/pages/PAGE-SLUG/{#APP_ID}?sk=app_{#APP_ID}
The problem is that I don't know what is the PAGE-SLUG. The tests I have run with the url above (using the PAGE-SLUG as anything) end up redirecting to the correct URL. However, knowing that Facebook is a very unstable platform, I would like to know it there is any better approach to building this redirect url.
EDIT: the above approach has a problem. The redirect loses the SSL protocol and uses the HTTP link when the facebook user doesn't use SSL by default.
It's very simple actually, you can call the Graph API with PHP like so:
$facebook->api("/{PAGE_ID}");
// change {PAGE_ID} to the page id you are redirecting back to
the return value is a json array with "link" in it -> that's the URL you are looking for :-)
Example Return:
{
"id": "XXXXXXXXX",
"name": "My Demo Page",
"picture": "",
"link": "https://www.facebook.com/pages/My-Demo-Page/XXXXXXXXX",
"likes": 123456,
"category": "Product/service",
"can_post": true,
"type": "page"
}
You can also query by the page name, if you know it, for example:
querying the Graph API with:
$facebook->api("/coca-cola");
Will result in:
{
"id": "40796308305",
"name": "Coca-Cola",
"picture": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-snc4/174560_40796308305_2093137831_s.jpg",
"link": "https://www.facebook.com/coca-cola",
"likes": 40680159,
"cover": {
"cover_id": "10150682306963306",
"source": "https://fbcdn-sphotos-a.akamaihd.net/hphotos-ak-snc7/s720x720/416803_10150682306963306_40796308305_9337341_812683101_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.",
"location": {
"latitude": -33.816989983333,
"longitude": 150.84844081667
},
"can_post": true,
"checkins": 80,
"talking_about_count": 297576,
"type": "page"
}
Edit:
A more clear explanation:
Call the Graph API with the current page id.
If the result is no false, then the redirect_uri would be the link
returned from the call.
Otherwise, the redirect_uri should be yourdomain.com/middle-page.php?page_id=XXX
If the user then accepts the application and the redirect_uri is the middle page,
you then call the Graph API again, but this time, you use the Access Token received
from Facebook. now you should have the real page url and you can add any additional
details you need (like ?sk_app=APP_ID)
According to Facebook own documentation, It's not clear what happens if the user decided not no accept the application. I think the user will redirect back to the redirect_uri, which then you can check if you have "user_id" in the signed_request, but I'm not 100% sure... Creating a simple app demo and checking :-)

How to redirect to a Facebook fanpage with ID of fanpage?

I have the ID of a facebook fanpage, and only the ID. Which link I have to build to redirect to this fanpage?
If you only want link that will bring you to the fanpage itself you may use:
http://facebook.com/ANY_FACEBOOK_ID
It'll work for any Facebook ID, no matter page, user, application
Update:
As discussed in comments to other answer there is a some downsides to the link described above:
This is in no way official way and it's not documented, so it may just stop working without any notice...
Any arguments passed to this link are removed on redirection to Page. (Using http://facebook.com/PAGEID?sk=notes will not redirect to Notes application)
So if you need to direct users not only to the page itself but to application on a Page you may use links like:
http://facebook.com/pages/-/PAGEID?sk=app_APPID
Well as you query the graph using the object id (user, page..group...etc):
https://graph.facebook.com/40796308305
{
"id": "40796308305",
"name": "Coca-Cola",
"picture": "http://profile.ak.fbcdn.net/hprofile-ak-snc4/157930_40796308305_262497158_s.jpg",
"link": "https://www.facebook.com/coca-cola",
"likes": 40005128,
"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.",
"location": {
"latitude": -33.816989983333,
"longitude": 150.84844081667
},
"can_post": true,
"checkins": 78,
"talking_about_count": 583000
}
Querying Facebook directly would also redirect to the "object" page:
https://www.facebook.com/40796308305 --> https://www.facebook.com/cocacola
https://www.facebook.com/579187142 --> https://www.facebook.com/ifaour
Yet this is not an official way. So I'm not sure if this could stop working in the future.

How to access Facebook Fan Page Photos within external Website

We are trying to utilize the facebook photo hosting and allow our visitors to view photos via our webpage that have been uploaded to our fan wall.
Does anyone know how this can be achieved?
Thank in advance!
Steven.
Using the social graph, you can do this, provided the script has an access token for your facebook page app ID or your photo permissions are set to be completely public.
Using the social graph, you basically access the photos via a REST like web service. The webservice call will return a JSON object of dataExample:
https://graph.facebook.com/cocacola/albums
(Photo albums for the Coca Cola fan page)
So the first step would be to retrieve the albums using a URL like the one above.
Traverse through the photo albums and get the object ID of the album you want.
{
"id": "455377148305",
"from": {
"name": "Coca-Cola",
"category": "Company",
"id": "40796308305"
},
"name": "Coca-Cola Fanmeile FIFA WM 2010",
"link": "http://www.facebook.com/album.php?aid=249745&id=40796308305",
"count": 20,
"type": "normal",
"created_time": "2010-10-22T15:53:36+0000",
"updated_time": "2010-10-22T15:55:23+0000",
"comments": {}
},
Once you have the object ID, you can access it by simply placing it as the first paramter of the graph URL. E.g:
https://graph.facebook.com/40796308305
From there, you should be able to grab the actual URL to the images (depending on permission settings)
{
"id": "40796308305",
"name": "Coca-Cola",
"picture": "http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs236.ash2/50516_40796308305_7651_s.jpg",
"link": "http://www.facebook.com/coca-cola",
"category": "Company",
"website": "http://www.coca-cola.com",
"username": "coca-cola",
"products": "Coca-Cola is the most popular and biggest-selling soft drink in history, as well as the best-known product in the world.\n\nCreated in Atlanta, Georgia, by Dr. John S. Pemberton, Coca-Cola was first offered as a fountain beverage by mixing Coca-Cola syrup with carbonated water. Coca-Cola was introduced in 1886, 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.",
"likes": 22264613
}