Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logging into Facebook without a Browser

I'm working on a script currently that needs to pull information down from a specific user's wall. The only problem is that it requires authentication, and the script needs to be able to run without any human interference. Unfortunately all I can find thus far tells me that I need to register an application, and then do the whole FB Connect dance to pull off what I want. Problem is that requires browser interaction, which I'm trying to avoid.

I figured I could probably just use httplib2, and login this route. I got that to work, only to find that with that method I still don't get an "access_token" in any retrievable method. If I could get that token without launching a browser, I'd be completely set. Surely people are crawling feeds and such without using FB Connect right? Is it just not possible, thus why I'm hitting so many road blocks? Open to any suggestions you all might have.

like image 665
f4nt Avatar asked Dec 28 '22 05:12

f4nt


2 Answers

What you are trying to do is not possible. You are going to have to use a browser to get an access token one way or another. You cannot collect username and passwords (a big violation of Facebook's TOS). If you need a script that runs without user interaction you will still need to use a browser to authenticate, but once you have the user's token you can use it without their direct interaction. You must request the "offline_access" permission to gain an access token that does not expire. You can save this token and then use it for however long you need.

like image 175
Nathan Totten Avatar answered Dec 30 '22 18:12

Nathan Totten


I've done this with my own account before using mechanize. You can log in to Facebook using something like the below and then just follow the links to where you want to go. This will print out the contents of you news feed.

#!/usr/bin/env python

import mechanize

browser = mechanize.Browser()
browser.set_handle_robots(false)
cookies = mechanize.CookieJar()
browser.set_cookiejar()
browser.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.7 (KHTML, like Gecko) Chrome/7.0.517.41 Safari/534.7')]

browser.select_form(nr=0)
browser.form['email'] = 'YOUR_EMAIL_ADDRESS'
browser.form['pass'] = 'YOUR_PASSWORD'
response = browser.submit()
print response.read()
like image 42
EverythingZen Avatar answered Dec 30 '22 18:12

EverythingZen