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?
4 Answers
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
}

- 249,484
- 69
- 436
- 539
-
A very good choice if you're working against user IDs; if it's not guaranteed, there's a more general way to handle URLs via the Graph API. See the answer below. – Tomer Gabel Feb 22 '12 at 15:13
-
1Note that if you get an `Unsupported get request`, the page [may be restricted](http://stackoverflow.com/q/6843796/241211). – Michael Dec 18 '14 at 15:10
-
2Still working, but now it needs an access token to read the resource. See more at https://developers.facebook.com/docs/graph-api/using-graph-api/?locale=en_US. – Duong Nguyen Oct 25 '16 at 03:44
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/

- 4,104
- 1
- 33
- 37
-
5for external urls. this is used for getting the open graph info for a site, not a fb object id for an internal object. – Jake Jan 22 '16 at 08:04
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":.

- 598
- 5
- 16
-
1Yes. Very much legal. We are just picking up this from html source – Risky Pathak Aug 13 '15 at 01:51
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.

- 1,176
- 1
- 13
- 29
-
This doesn't seem to work. This would create a URL object. https://developers.facebook.com/docs/graph-api/reference/v2.8/url/ – Brad Jan 05 '17 at 23:51
-
Then you probably did a request on a personal facebook page, not an official page that you have to like. There was no need to downvote this answer. We have this up and running. – KJS Jan 06 '17 at 20:58
-
Can you provide a full example? Here's a post from an official page from CNN, and your method does not appear to work. `GET /v2.8/https%3A%2F%2Fwww.facebook.com%2Fcnn%2Fposts%2F10155873400471509` (with access token...using the Graph API explorer) I just get back a "website" object, and nothing about the public post on an official public page. – Brad Jan 06 '17 at 22:00