Exemplo n.º 1
0
def register(u_id, a_token):
    try:
        f = FBUser.objects.get(pk = u_id)
        print "%s found, updating access_token %s" % (u_id, a_token)
        f.access_token = a_token

    except Exception as e:
        f = FBUser(id = u_id, access_token = a_token)

    f.save()
Exemplo n.º 2
0
def update_profile_for_friend(f, u_id):
    found = False
    
    try:
        f = FBUser.objects.get(pk = u_id)
        found = True
    except Exception as e:
        pass

    if not found:
        url = "https://graph.facebook.com/%s?access_token=%s" % (u_id, f.access_token)
        print "calling url " + url

        usr_json = urllib.urlopen(url).read()
        usr_obj = json.loads(usr_json)


        print "usr obj %s" % (usr_obj)
    
        f = FBUser(id = int(usr_obj["id"]))
        f.name = usr_obj["name"]
        f.link = usr_obj["link"]
        f.gender = usr_obj["gender"]
        f.locale = usr_obj["locale"]

        print ("About to save usr %s " % (f)).encode('utf-8')
        f.save()
        print ("usr saved %s" % (f)).encode('utf-8')