Created
June 1, 2013 14:43
-
-
Save sixinli/5690639 to your computer and use it in GitHub Desktop.
post facebook status
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cookielib | |
import urllib | |
import urllib2 | |
# set these to whatever your fb account is | |
fb_username = "[email protected]" | |
fb_password = "secretpassword" | |
class WebGamePlayer(object): | |
def __init__(self, login, password): | |
""" Start up... """ | |
self.login = login | |
self.password = password | |
self.cj = cookielib.CookieJar() | |
self.opener = urllib2.build_opener( | |
urllib2.HTTPRedirectHandler(), | |
urllib2.HTTPHandler(debuglevel=0), | |
urllib2.HTTPSHandler(debuglevel=0), | |
urllib2.HTTPCookieProcessor(self.cj) | |
) | |
self.opener.addheaders = [ | |
('User-agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/536.26.14 (KHTML, like Gecko) Version/6.0.1 Safari/536.26.14'), | |
('X-Forwarded-For', '129.49.6.141') | |
] | |
# need this twice - once to set cookies, once to log in... | |
var = self.loginToFacebook() | |
var = self.loginToFacebook() | |
def loginToFacebook(self): | |
""" | |
Handle login. This should populate our cookie jar. | |
""" | |
login_data = urllib.urlencode({ | |
'email' : self.login, | |
'pass' : self.password, | |
}) | |
response = self.opener.open("https://www.facebook.com/login.php", login_data) | |
return ''.join(response.readlines()) | |
def postStatus(self, meg): | |
""" | |
Post a new status. | |
""" | |
status_data = urllib.urlencode({ | |
'fb_dtsg':'AQDoqXco', | |
'xhpc_context':'home', | |
'xhpc_ismeta':'1', | |
'xhpc_timeline':'', | |
'xhpc_composerod':'u_0_i', | |
'xhpc_targetid':'590245294', | |
'xhpc_message': meg, | |
'xhpc_message_text': meg, | |
'is_explicit_place':'', | |
'composertags_place':'', | |
'composertags_place_name':'', | |
'action_type_id[0]':'', | |
'object_str[0]':'', | |
'object_id[0':'', | |
'composertags_city':'', | |
'disable_location_sharing':'false', | |
'composer_predicted_city':'', | |
'audience[0][value]': '80', | |
'nctr[_mod]':'pagelet_composer', | |
'_user':'590245294', | |
'_a':'1', | |
'_dyn':'7n8ahyj35CFwXAU', | |
'_req':'r', | |
'phstamp':'16581681111138899111481', | |
}) | |
response = self.opener.open("https://www.facebook.com/ajax/updatestatus.php", status_data) | |
return ''.join(response.readlines()) | |
me = WebGamePlayer("[email protected]", "password") | |
me.postStatus('this is sent from pyCharm yeah') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment