Search code examples
facebookfacebook-graph-apipython-requests

Facebook Graph Api : Searching name in facebook


Hello how i can possible to search name on facebook graph api like "John Doe" instead of username or userid? I'm using requests module of python thanks


Solution

  • Unfortunately facebook-graph API doesn't have endpoints for searching users but you can simply use the fb package for logging-in and automate your search using the module facebook-scraper package

    search fb username

    you can get the cookies.txt using cookie extension that extracts local cookie file into text.

    from facebook_scraper import get_profile
    get_profile("zuck") # Or get_profile("zuck", cookies="cookies.txt")
    
    {'About': "I'm trying to make the world a more open place.",
     'Education': 'Harvard University\n'
                  'Computer Science and Psychology\n'
                  '30 August 2002 - 30 April 2004\n'
                  'Phillips Exeter Academy\n'
                  'Classics\n'
                  'School year 2002\n'
                  'Ardsley High School\n'
                  'High School\n'
                  'September 1998 - June 2000',
     'Favourite Quotes': '"Fortune favors the bold."\n'
                         '- Virgil, Aeneid X.284\n'
                         '\n'
                         '"All children are artists. The problem is how to remain '
                         'an artist once you grow up."\n'
                         '- Pablo Picasso\n'
                         '\n'
                         '"Make things as simple as possible but no simpler."\n'
                         '- Albert Einstein',
     'Name': 'Mark Zuckerberg',
     'Places lived': [{'link': '/profile.php?id=104022926303756&refid=17',
                       'text': 'Palo Alto, California',
                       'type': 'Current town/city'},
                      {'link': '/profile.php?id=105506396148790&refid=17',
                       'text': 'Dobbs Ferry, New York',
                       'type': 'Home town'}],
     'Work': 'Chan Zuckerberg Initiative\n'
             '1 December 2015 - Present\n'
             'Facebook\n'
             'Founder and CEO\n'
             '4 February 2004 - Present\n'
             'Palo Alto, California\n'
             'Bringing the world closer together.'}
    

    credits to : facebook-scraper documentation