6 luglio 2012

How to simply retrieve a Facebook ID using Graph API

If the owner of a Facebook Fan Page or of an account has set the username and you want to retrieve his ID, you can simply get it through a Graph API request.

To do that you only have to change the "www" subdomain with the "graph" one on the URL. For example, this is my Facebook profile URL:


you can make the necessary API call from the following URL:


And the response should be:

   "id": "1040530537",  
   "name": "Marco Valsecchi",  
   "first_name": "Marco",  
   "last_name": "Valsecchi",  
   "link": "https://www.facebook.com/marco.valsecchi",  
   "username": "marco.valsecchi",  
   "gender": "male",  
   "locale": "it_IT"  

this is a JSON object with a javascript/text content type.