facebookfacebook-graph-api

Identifying a Facebook user id from a url?


I've been playing around with the Facebook graphs API for a while, and to the best of my knowledge you shouldn't be able to get a Facebook user's id from their username.

I then came accross stalkscan.com and note that they do just that. You provide a Facebook URL and the resulting queries contain that usernames profile id.

How can I achieve a similar result with or without the graphs API?


Solution

  • You can get a facebook user id by using the following endpoint:

    URL /?id={url}
    

    {url} represents an external URL as it relates to the Facebook social graph - shares and comments from the URL on Facebook, and any Open Graph objects associated with the URL. (e.g. a user, a page...).

    With Python, you can use something like this:

    import requests
    
    USER_URL = '' # your link
    ACCESS_TOKEN = '' # your credentials
    params= {'id': USER_URL,'access_token': ACCESS_TOKEN}
    fb_graph = "https://graph.facebook.com/v2.7/"
    
    r = requests.get(fb_graph, params=params)
    fb_id = r.json().get('id')
    
    print('Facebook User ID: %s' % fb_id)
    

    Full documentation of the graph API is available here.