[Tutor] Facebook login using python

Kwpolska kwpolska at gmail.com
Mon Jan 28 18:01:45 CET 2013


I will kill the one who invented this bullshit with the Reply button.
(sent 1 h 13 min ago)
---------- Forwarded message ----------
From: Kwpolska <kwpolska at gmail.com>
Date: Mon, Jan 28, 2013 at 4:48 PM
Subject: Re: [Tutor] Facebook login using python
To: Aaron Misquith <aaronmisquith at gmail.com>


On Mon, Jan 28, 2013 at 4:40 PM, Aaron Misquith <aaronmisquith at gmail.com> wrote:
> I am working on a program which is used to login to facebook, get my friend
> lists using graph api and export them into pdf format.
> So far i'm able to login with facebook and get the friend list. I would like
> if someone is able to provide me a code to export the output to pdf. Another
> thing is that i'm hardcoding username, password and access tokens; is there
> anyway this can be obtained using user input?
>
> Code:
>
> import urllib2, cookielib, re, os, sys
> from facepy import GraphAPI
> class Facebook():
> def __init__(self, email, password):
> self.email = email
> self.password = password
>
> cj = cookielib.CookieJar()
> opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
> opener.addheaders = [('Referer', 'http://login.facebook.com/login.php'),
> ('Content-Type', 'application/x-www-form-urlencoded'),
> ('User-Agent', 'Mozilla/8.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.7)
> Gecko/20091221 Firefox/3.5.7 (.NET CLR 3.5.30729)')]
>
> self.opener = opener
>
> def login(self):
> url = 'https://login.facebook.com/login.php?login_attempt=1'
> data =
> "locale=en_US&non_com_login=&email="+self.email+"&pass="+self.password+"&lsd=20TOl"
>
> usock = self.opener.open('http://www.facebook.com')
> usock = self.opener.open(url, data)
> if "Logout" in usock.read():
> print "Logged in."
> else:
> print "failed login"
> print usock.read()
> sys.exit()
> f = Facebook("Enter email", "Password")
> f.login()
> graph=GraphAPI('Enter Access code from fql in developer's page')
>
> nik=graph.fql('select uid, name, friends from user where uid in (select
> first_name, middle_name, last_name from friend where uid1 = me())')
>
> print nik
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

1. Code indentation was lost in your message.  Everything below is
based on guessing, guessing and guessing.
2. In order to get user data, do (assuming Python 2):

import getpass
self.email= raw_input('E-mail address: ')
self.password = getpass.getpass('Password: ')
devcode = raw_input(Developer access code: ')

Although you should provide the user with the tokens, using the same
methods REAL developers use, i.e. app authentication.

3. http://lmgtfy.com/?q=python+pdf
--
Kwpolska <http://kwpolska.tk> | GPG KEY: 5EAAEA16
stop html mail                | always bottom-post
http://asciiribbon.org        | http://caliburn.nl/topposting.html


More information about the Tutor mailing list