1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to convert List Facebook User IDs to Usernames/Emails?

Discussion in 'FaceBook' started by prosper109, Jun 18, 2015.

  1. prosper109

    prosper109 Junior Member

    Joined:
    Mar 3, 2013
    Messages:
    169
    Likes Received:
    14
    I'm looking to convert a list of user IDs to usernames. Thanks
     
  2. weedsmoker

    weedsmoker Junior Member

    Joined:
    May 2, 2011
    Messages:
    190
    Likes Received:
    79
    Python example:

    Code:
    import requests
    import json
    import time
    
    headers = {
        'content-type': 'application/json',
        'User-Agent': 'Mozilla/5.0 (Windows NT 5.1; rv:18.0) Gecko/20140101 Firefox/30.0'
    }
    
    access_token = 'YOUR ACCESS TOKEN'
    
    profile_ids = '''100000111992548
    100000111992548
    100000111992548'''.splitlines()
    
    for profile_id in profile_ids:
        try:
            url = 'https://graph.facebook.com/%s/?fields=username&access_token=%s' % (profile_id, access_token)
            response = requests.get(url, headers=headers)
            if response.status_code == requests.codes.ok:
                print(json.loads(response.text)['username'])
            time.sleep(0.5)
        except:
            pass