Given a facebook url such as http://facebook.com/cnn, is there any way to get the ID of that page short of scraping it?
It is better (and legal) to do this with graph API. Just perform API request to https://graph.facebook.com/cnn and get id from the response.
Here is the response for cnn:
{
"id": "5550296508",
"name": "CNN",
"picture": "http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs178.ash2/41813_5550296508_728_s.jpg",
"link": "http://www.facebook.com/cnn",
"category": "Company",
"website": "www.cnn.com\nwww.ireport.com\n",
"username": "cnn",
"company_overview": "TRIVIA FROM THE CNN TOUR...",
"products": "CNN US...",
"likes": 1689936
}
Facebook's own Graph API supports it. From the documentation:
The "ids" query parameter also accepts URLs. This is useful for
finding IDs of URLs in the Open Graph. For example:
https://graph.facebook.com/?ids=http://www.imdb.com/title/tt0117500/
As of Today(28th July 2015), There still exists an easy way to get page(or user's) id.
Browse to facebook page(or user) url. The syntax is https://www.facebook.com/[username or pagename]
Right click to view source and then search for string "pageID": in case of page. The numeric id next to searched string will be id.
In case of user, search for "uid":.
Been working with it today. So, for people who want to know how this works. Use this:
https://graph.facebook.com/<the_fb-address>?access_token=$accessToken
And remember: this is only for pages. Not user pages/friends' timelines etc.
Those will have to approve your Facebook App first before you can read their profiles.
Related
I'm a little out of my element here so forgive me if I'm not asking a the question correctly, but I'm trying to take a list of Facebook User URLs and find the User ID. I found another SE post that showed how to do this for one user, which basically took a graph.facebook url and appended the User URL to the end like so: http://graph.facebook.com/fql?q=select%20url%2C%20id%2C%20type%2C%20site%20from%20object_url%20where%20url%20%3D%20%22http%3A%2F%2Fwww.facebook.com%2F[firstname.lastname]%22
Which outputs:
{
"data": [
{
"url": "http://www.facebook.com/firstname.lastname",
"id": [userID],
"type": "profile",
"site": "www.facebook.com"
}
]
}
I'm wondering if there's a way I can make a batch request with big list of URLs, and easily store those user IDs in an excel sheet. Unfortunately I tried reading up on the facebook developers API overview but I don't really understand any of it, nor how to use cURL or urllib. Would anyone be able to help me out?
Insights API works properly for link feed but it doesn't work for photo feed. For photo feed, Insights API returns 0 or empty even though Insights page shows a high reach and engagement rate.
Here is the url pattern of my photo feed:
https://www.facebook.com/[PAGE]/photos/a.xxx.xxx.[PAGE ID]/[POST ID]/
Insights API returns:
{
"id": "[PAGE ID]_[POST ID]/insights/post_story_adds_by_action_type_unique/lifetime",
"name": "post_story_adds_by_action_type_unique",
"period": "lifetime",
"values": [
{
"value": [
]
}
],
"title": "Lifetime Talking About This (Post) by action type",
"description": "Lifetime: The number of unique people who created a story about your Page post by interacting with it. (Unique Users)"
}
I've been struggeling with the same questions... one thing I can tell you is, that you most likely used a wrong id for you photo post.
Please ensure that you ONLY use ID's retrieved by a facebook api. So this is a sample process:
1. Note your page-id
2. Use GRAPH to query <url-to-graph>/<page_id>/feed?access_token=<your_token>
3. From the response, take the photo-post-id you want to analyze
4. Use GRAPH to query <url-to-graph>/<id_from_step_3>/insights/?access_token=<your_token>
5. Check the metrics returned from step 4 and enjoy!
Please keep in mind that there's an undocumented need to add your page_id to any post_id. So every replacement of {post-id} as it is written in the FB api's will be _.
Hope that helps...
I have a list of FB ids, is there a canon way of constructing their FB url without a graph query?
For example, I have ids 3, 4, 5, and i want the Facebook URL for them without using the graph api and save them down
UPDATE 2: This information is no more given by facebook. There is an official announcement for the behavior change (https://developers.facebook.com/blog/post/2018/04/19/facebook-login-changes-address-abuse/) but none for its alternative.
Yes, Just use this link and append your ID to the id parameter:
https://facebook.com/profile.php?id=<UID>
So for example:
https://facebook.com/profile.php?id=4
Will redirect you automatically to https://www.facebook.com/zuck Which is Mark Zuckerberg's profile.
If you want to do this for all your ids, then you can do it using a loop.
If you'd like, I can provide you with a snippet.
UPDATE: Alternatively, You can also do this:
https://facebook.com/<UID>
So that would be: https://facebook.com/4 which would automatically redirect to Zuck!
Accepted answer didn't work for me, this does:
https://www.facebook.com/app_scoped_user_id/10152384781676191
The easiest and the most correct (and legal) way is to use graph api.
Just perform the request: http://graph.facebook.com/4
which returns
{
"id": "4",
"name": "Mark Zuckerberg",
"first_name": "Mark",
"last_name": "Zuckerberg",
"link": "http://www.facebook.com/zuck",
"username": "zuck",
"gender": "male",
"locale": "en_US"
}
and take the link key.
You can also reduce the traffic by using fields parameter: http://graph.facebook.com/4?fields=link to get only what you need:
{
"link": "http://www.facebook.com/zuck",
"id": "4"
}
The marked answer seems outdated and it won't work.
Facebook now only gives unique ID related to app which isn't equal to userId and profileUrl and username will come out to be empty.
Doing me?fields=id,name,links is also depreciated after Graph Version 2.4
The only option now is to request for user_links permission from your developer console.
and the pass it in scope when doing facebook login
scope: ['user_link'] }
or by doing an api call
As of now (NOV-2019), graph.api V5.0
graph API says, refer graph api
A link to the person's Timeline. The link will only resolve if the person clicking the link is logged into Facebook and is a friend of the person whose profile is being viewed.
I've collected info together:
add into scope user_link, see https://developers.facebook.com/docs/facebook-login/permissions/
add into fields request link (e.g. https://graph.facebook.com/me?fields=link,name,email)
get link from answer. Be aware of field length- in my case it is 202: https://www.facebook.com/app_scoped_user_id/YXNpZADpBWEd0SlhFZAElYa3BQT3U3Tm4xWVRLSlJfYUdUM3Y4YmIwQjBaRkM0VDBMNURQdUhhYk5NRDJoR1ZA5ZA1JOdGNwampsSTQyMDQwbW93bkp0dnZAmOXg3NTFISFVZAQlRscWQ5eEZAvcU4xZAC1B/
And finaly: it doen't work without additional Facebook permission check:(
We're working on developing a program that will (hopefully) automatically swap out creative with new creative once a certain like threshold is met (i.e. if 100 people like the page, something new appears). Can we add coding so our system is able to tell how many "likes" are generated? I know that the number of likes are displayed, I'm just not sure if there is a way for a program to actually read how many likes there are.
I don't see if in any of the Facebook attributes in the developer's platform.
What you'll have to do is acquire an access token for your page and then query the facebook platform for the number of likes periodically (possibly with a cron job of sorts).
You can read more about how to get the page access token at this URL
https://developers.facebook.com/docs/authentication/
Facebook has given us a great took to help us mine all the data it holds - its called the Graph API Explorer and with it you can see what data will be returned when you query the API. When you query the API with only the page_id you'll get a response similar to this :
{
"id": "XXXXXXXXX",
"name": "My Awesome Page",
"picture": "foo.jpg",
"link": "https://www.facebook.com/pages/XXXXXXXX",
"likes": 345,
"category": "Product/service",
"website": "XXXXXXX",
"founded": "2011",
"description": "...",
}
For more information about how to use the Graph API you can see this link :
https://developers.facebook.com/docs/reference/api/
Facebook does provide good documentation:
http://developers.facebook.com/docs/reference/api/page/
As you can see there, there is a field "likes" containing the number (count) of likes for a page.
I'm developing an app on facebook and want to get the last date that the user of my app liked anything on Facebook.
It doesn't matter if its a page, post, comment, link or anything else you can like on Facebook.
Is it possible?
Thanks!
Actually, you can. (Probably added since Peter Bailey wrote his answer.)
Each like has a created_time field. The likes connection of a user object in the graph API returns most recently liked objects first. So if you just fetch the most recently liked item and check its creation time, you can get this data.
The API GET call would be:
/me/likes?limit=1
and the result would look like:
{
"data": [
{
"name": "Steve Jobs",
"category": "Business person",
"id": "113529011990795",
"created_time": "2011-09-23T02:22:22+0000"
}
],
}
You can play with this on the Graph API Explorer.
No.
A timestamp or other type of date value is not part of the information retrievable for likes. Not through FQL nor through the Graph API.