Update Facebook Page's status using pyfacebook

依然范特西╮ 提交于 2019-12-04 15:50:40

In the definition of login, particularly in the docstring, it appears as though the intended behavior is to open up a browser in order to have you log in that way.

def login(self, popup=False):
    """Open a web browser telling the user to login to Facebook."""
    import webbrowser
    webbrowser.open(self.get_login_url(popup=popup))

Looking at the facebook page User:PyFacebook_Tutorial that you linked, it looks like the example with login is a "Desktop Applications" example. You want to follow the "Web Applications" section. I'd encourage you to simply press ahead with the tutorial there.

If you want to login to your facebook profile page I have managed to do it with this script:

Save this file as fb_login.py and in the same folder create a file fb_test.html

I successfully logged in as you can prove by viewing on your browser the fb_test.html or searching for your name in the plain text.

Does anyone knows how to login with simple Authedication credentials and not with SECRET AND API key that you need to make application?

import urllib, urllib2, cookielib

user = 'put_your_mail_here'
passwd = 'put_your_password_here'

file = './fb_test.html'
url_login = "https://login.facebook.com/login.php?"
url_action = "https://login.facebook.com/login.php?login_attempt=1"
url_topic = "http://www.facebook.com/profile.php?id=___put_your_profile_Number_here"
url_index = "https://login.facebook.com/login.php?"

def login(user, password, url_action):
    cj = cookielib.LWPCookieJar()
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor())
    urllib2.install_opener(opener)
    opener.addheaders=[('Content-Type','application/x-www-form-urlencoded'),('Connection','keep-alive'),('User-Agent','Mozilla/5.0')]
    params = urllib.urlencode({'action':url_action , 'referer':url_index, 'email':user, 'pass':passwd, 
                                  'loginTrue':"login"})

f = opener.open(url_action, params)
    f.close()
    f = opener.open(url_action, params)
    f.close()
    return opener

def get_source_code( opener, url_x ):
    f = opener.open(url_x)
    data = f.read()
    print type(data)
    f.close()
    return data

def keep_log( data, file ):
    f = open(file, 'w')
    f.write(data)
    f.close()

opener = login(user, passwd, url_action)
src_code = get_source_code(opener, url_topic)
keep_log(src_code, file)
print src_code
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!