Exemplo n.º 1
0
def save_user(access_token, auth_code):
    """
    updates/saves a user in the database
    and returns the fb_info and the user's saved id about it
    """
    
    #get info
    fb_api = FacebookApi.new(access_token)
    fb_user_info = fb_api.get_info()
    
    #save info into db
    fb_user = addupdate_facebook_user(fb_user_info["id"], fb_user_info["name"], fb_user_info.get("first_name",None), fb_user_info.get("middle_name",None), 
                                fb_user_info.get("last_name",None), fb_user_info.get("gender",None), fb_user_info.get("username",None), fb_user_info["link"])
    user = addupdate_user(fb_user.id, fb_user_info["email"], access_token, auth_code)
    update_social_graph(access_token, fb_user)
    
    return fb_user_info, user
Exemplo n.º 2
0
def update_social_graph(access_token, fb_user=None):
    """
    Note: Include fb_user for performance (1 less FB API to call)
    """
    
    #get friends
    fb_api = FacebookApi.new(access_token)
    all_friends = fb_api.get_friends()
    if not fb_user:
        fb_user = get_facebook_user(fb_api.get_info()["id"])
    
    #save friends into db
    if "data" in all_friends:
        for friend in all_friends["data"]:
            fb_friend = addupdate_facebook_user(friend["id"], friend["name"], None, None, None, None, None, None, commit=False)
            add_friend_connection(fb_user, fb_friend, commit=False)
            
    from db import db
    db.session.commit()

    return all_friends