Esempio n. 1
0
def get_fb_friends(request):
    #should be a one time thing
    username = request.session['username']
    token = request.GET['token']
    fb_id = request.GET['user']
    users.objects.filter(username=username).update(fb_id=fb_id,profile_pic="http://graph.facebook.com/" + fb_id + "/picture")
    fb_friends = simplejson.loads(urllib2.urlopen("https://graph.facebook.com/" + fb_id + "/friends?access_token=" + token).read())
    for friend in fb_friends['data']:
        ia = fb_friend_map(fb_id=fb_id,fb_friend_id=friend['id'])
        ia.save()
    return HttpResponseRedirect("/friends")
Esempio n. 2
0
def load_fb_friends_new(fb_id,token,username):
    #take out the fb_id check, because ghost accounts will have fb ids, and we stil want to be able to load them.  And the user should only be able to re-sync friends, not load up again after they've loaded already, so we should
    #be okay with not having this check in place.
    #if len(users.objects.filter(username=username)[0].fb_id) > 0:
        #response = {"response": {"message": "fb friends loaded"}}
        #return HttpResponse(simplejson.dumps(response),status=201,mimetype='application/json')
    fb_friends = simplejson.loads(urllib2.urlopen("https://graph.facebook.com/" + fb_id + "/friends?access_token=" + token).read())
    for friend in fb_friends['data']:
        ia = fb_friend_map(fb_id=fb_id,fb_friend_id=friend['id'])
        ia.save()
    users.objects.filter(username=username).update(fb_token=token,fb_id=fb_id,profile_pic="http://graph.facebook.com/" + fb_id + "/picture")
    response = {"response": {"message": "fb friends loaded"}}
    return HttpResponse(simplejson.dumps(response),status=201,mimetype='application/json')
Esempio n. 3
0
def load_fb_friends(request):
    val = validate_user(request)
    if val:
        return val
    username = request.session['username']
    if len(users.objects.filter(username=username)[0].fb_id) > 0:
        response = {"response": {"message": "fb friends loaded"}}
        return HttpResponse(simplejson.dumps(response),status=201,mimetype='application/json')
    if request.method == 'POST':
        token = request.POST['token']
        fb_id = request.POST['user']
    elif request.method == 'GET':
        token = request.GET['token']
        fb_id = request.GET['user']
    fb_friends = simplejson.loads(urllib2.urlopen("https://graph.facebook.com/" + fb_id + "/friends?access_token=" + token).read())
    for friend in fb_friends['data']:
        ia = fb_friend_map(fb_id=fb_id,fb_friend_id=friend['id'])
        ia.save()
    users.objects.filter(username=username).update(fb_token=token,fb_id=fb_id,profile_pic="http://graph.facebook.com/" + fb_id + "/picture")
    response = {"response": {"message": "fb friends loaded"}}
    return HttpResponse(simplejson.dumps(response),status=201,mimetype='application/json')
Esempio n. 4
0
    response = {"response": {"message": "fb friends loaded"}}
    return HttpResponse(simplejson.dumps(response),status=201,mimetype='application/json')
load_fb_friends = csrf_exempt(load_fb_friends)

def sync_fb_friends(request):
    fb_id = request.GET['fb_id']
    fb_name = request.GET['fb_name']
    fb_token = request.GET['fb_token'] 
    try:
        res = simplejson.loads(urllib2.urlopen("https://graph.facebook.com/" + fb_id + "/friends?access_token=" + fb_token).read())
    except Exception, e:
        response = {'response':{'message':'pre-condition failed'}}
        return HttpResponse(simplejson.dumps(response),status=412,mimetype='application/json')
    d = fb_friend_map.objects.filter(fb_id=fb_id).delete()
    for friend in res['data']:
        ia = fb_friend_map(fb_id=fb_id,fb_friend_id=friend['id'])
        ia.save()
    response = {"response": {"message": "fb friends synchronized"}}
    return HttpResponse(simplejson.dumps(response),status=201,mimetype='application/json')

def load_fb_friends_new(fb_id,token,username):
    #take out the fb_id check, because ghost accounts will have fb ids, and we stil want to be able to load them.  And the user should only be able to re-sync friends, not load up again after they've loaded already, so we should
    #be okay with not having this check in place.
    #if len(users.objects.filter(username=username)[0].fb_id) > 0:
        #response = {"response": {"message": "fb friends loaded"}}
        #return HttpResponse(simplejson.dumps(response),status=201,mimetype='application/json')
    fb_friends = simplejson.loads(urllib2.urlopen("https://graph.facebook.com/" + fb_id + "/friends?access_token=" + token).read())
    for friend in fb_friends['data']:
        ia = fb_friend_map(fb_id=fb_id,fb_friend_id=friend['id'])
        ia.save()
    users.objects.filter(username=username).update(fb_token=token,fb_id=fb_id,profile_pic="http://graph.facebook.com/" + fb_id + "/picture")