Lookup any Username on FACEBOOK

Discussion in 'Python' started by lionaneesh, Nov 5, 2011.

  1. lionaneesh

    lionaneesh Active Member

    Joined:
    Mar 21, 2010
    Messages:
    848
    Likes Received:
    224
    Trophy Points:
    43
    Occupation:
    Student
    Location:
    India
    In this tutorial we'll be making a small yet effective application rather code snippet to Lookup Any Username on Facebook. The Code Below Uses the Graph API, The Graph API (as defined by Facebook) is the core of Facebook Platform , It allows reading and Writing access to Facebook. It provides a simple view of social graph uniformly representing objects (like people, photos, events, and pages) and the connections between them (friendships, likes, and photo tags).

    To make the data handling even more simpler , Facebook returns all responses are JSON objects.

    Code



    To make it simple and Short I am using Python , but the same can be done in any other language!


    main.py
    Code:
     #!/bin/python
     import sys # for command line arguments 
     from urllib import urlopen 
     import json # for parsing 
     from StringIO import StringIO 
      
     if len(sys.argv) != 2 : # The Program Name and the Username 
         sys.exit("Usage : "+sys.argv[0]+" Username\n"); 
      
     username = sys.argv[1]; 
      
     data = urlopen("http://graph.facebook.com/"+username).read(); 
      
     io = StringIO(data); 
     user = json.load(io);   
      
     # lets parse it now! :) 
      
     print "ID\t: " , user['id'] ,"\nName\t: " , user['name'] , "\nGender\t: ", user['gender'], "\nlocale\t: " , user['locale']; 
     
    Usage :-
    Code:
     Usage : main.py Username 
     
    Sample Output :-
    Code:
     >>python main.py lionaneesh 
    
    
     ID    :  1203545662  
     Name    :  Aneesh Dogra  
     Gender    :  male  
     locale    :  en_US 
     
    That's all for this tutorial , Stay tuned for more! :)
     
  2. lionaneesh

    lionaneesh Active Member

    Joined:
    Mar 21, 2010
    Messages:
    848
    Likes Received:
    224
    Trophy Points:
    43
    Occupation:
    Student
    Location:
    India
    Thanks for Accepting , Hoping the Readers would find it useful! :)
     
  3. state

    state New Member

    Joined:
    Sep 14, 2011
    Messages:
    30
    Likes Received:
    0
    Trophy Points:
    0
    Kindly explain what is the logic of the program.I will try to implement the logic using JAVA.
    Tank You
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice