Facebook – How to get page_id from facebook url

facebookfacebook-graph-apiurl

my question is how get facebook page_id starting from a simple fb url. For example:

Actually if the url match the string "facebook.com/pages/" I call:

else I call:

This approach seems to work well, but it is really empirical and looking at documentation I don't see any suggestion.
What do you think about?

Best Answer

I'm not quite sure what you're asking but I think what you're talking about is trying to get the id of a page that you only know by its "vanity url" or "nickname".

Basically you can do a facebook graph api request to the "vanity url" and then grab the id from the provided request.

For example... if you open the Facebook graph API explorer https://developers.facebook.com/tools/explorer?method=GET&path=coca.cola.

or make a request to http://graph.facebook.com/coca.cola

you can see in the response you get "id": "40796308305" which is the page ID you are talking about.

Navigating to http://www.facebook.com/40796308305 should prove that.

Hope that helps.