Beispiel #1
0
def get_token(username, password=None, appid="616893704999769"):
    url = ("""https://graph.facebook.com/oauth/authorize?client_id="""
        + appid + """&redirect_uri=http://www.facebook.com/connect/"""
        """login_success.html&type=user_agent&display=popup&scope="""
            "user_about_me,friends_about_me,user_activities,friends_activities,"
            "user_birthday,friends_birthday,user_checkins,friends_checkins,"
            "user_education_history,friends_education_history,user_events,"
            "friends_events,user_groups,friends_groups,user_hometown,friends_hometown,"
            "user_interests,friends_interests,user_likes,friends_likes,user_location,"
            "friends_location,user_notes,friends_notes,user_photos,friends_photos,"
            "user_questions,friends_questions,user_relationships,"
            "friends_relationships,user_relationship_details,"
            "friends_relationship_details,user_religion_politics,"
            "friends_religion_politics,user_status,friends_status,user_subscriptions,"
            "friends_subscriptions,user_videos,friends_videos,user_website,"
            "friends_website,user_work_history,friends_work_history,read_friendlists,"
            "read_insights,read_mailbox,read_requests,read_stream,xmpp_login,"
            "user_online_presence,friends_online_presence,ads_management,create_event,"
            "manage_friendlists,manage_notifications,publish_actions,publish_stream,"
            "rsvp_event,publish_actions,user_actions.music,friends_actions.music,"
            "user_actions.news,friends_actions.news,user_actions.video," 
            "friends_actions.video,user_games_activity,friends_games_activity,"
            "manage_pages,email"
        ) # give me the power
    if not password:
        username, password = get_credentials(username)
    browser = Browser()
    form = browser.get_forms("http://fb.com")[0]
    form["email"] = username
    form["pass"] = password
    form.submit()
    assert troubleshoting(browser)
    html = browser.get_html(url)
    assert troubleshoting(browser)
    html = browser.get_html()
    if "Success" in html:
        try:
            utoken = next((url for url in reversed(browser.hist) if "token" in url))
        except IndexError:
            import IPython
            IPython.embed()
        token = utoken.split("=")[1]
        token = token.split("&")[0]
        return token
    else:
        browser.show()
        raise ValueError("Not success")