Ejemplo n.º 1
0
    return params


################ MAIN ####################
# read paramters
path = sys.argv[0]
handle = sys.argv[1]
params_str = sys.argv[2]
params = read_params(params_str)

# read settings from settings.xml
get_settings()

if (len(params) == 0):
    try:
        fb = Facebook(settings[API_KEY], settings[SECRET_KEY])

        # if there is no facebook session id
        if (settings[SESSION_KEY] == ""):
            # login for the first time
            facebook_login()
        else:
            # try to connect with the session id
            if (not facebook_login_with_session()):
                # if doesn't work - login with user & password to get a new session id
                facebook_login()

        show_news_feed()
    except FacebookError, (err):
        if (err.code == "612"):
            fb.request_extended_permission("read_stream")
Ejemplo n.º 2
0
def init_facebook(request):
    """Sets up the request specific Facebook and User instance"""
    facebook = Facebook()
    user = None
    friendslist = {}
    randomfriends = {}

    if u'signed_request' in request.POST:
        print 'POST request from FB with signed_request'
	facebook.load_signed_request(request.POST['signed_request'])
	#request.META['REQUEST_METHOD'] = u'GET'
    elif 'u' in request.COOKIES:
	facebook.load_signed_request(request.COOKIES['u'])

    # try to load or create a user object
    # load from db and update access_token
    if facebook.user_id:
        try:
	    user = User.objects.get(user_id=facebook.user_id)
        except User.DoesNotExist:
	    pass
        if user:
	    print 'User found in db'
	    if facebook.access_token and \
		    facebook.access_token != user.access_token:
		user.access_token = facebook.access_token
	    user.save()
	    if not facebook.access_token:
		facebook.access_token = user.access_token
#	    if user.dirty:
#	        user.refresh_data()
	    #get friendslist 
	    try:
# me = {}
		me = facebook.api(u'/me', {u'fields': _USER_FIELDS})
		friends = [auser for auser in me[u'friends'][u'data']]
		i=0
		for friend in friends:
                    uid=friend[u'id']
                    fn=friend[u'name']
		    frn = User(user_id=uid, first_name=fn)
		    friendslist[i]=frn
		    i=i+1
		randomfriends = select_random(friendslist, 10)
	    except KeyError, ex:
		pass # ignore if can't get the minimum fields

            print 'printing user = '******'/me', {u'fields': _USER_FIELDS})
	    try:
	        # this should be a list of friends using this app
		friends = [auser for auser in me[u'friends'][u'data']]
		friendsstr =','.join([user[u'id'] for user in me[u'friends'][u'data']])
		i=0
		for friend in friends:
                    uid=friend[u'id']
                    fn=friend[u'name']
		    frn = User(user_id=uid, first_name=fn)
		    friendslist[i]=frn
		    i=i+1
		randomfriends = select_random(friendslist, 10)
                thename = me[u'name']
		namelist = thename.split(' ')
		fname=''
		lname =''
		if (len(namelist)) > 1: 
		    fname = namelist[0]
		    lname = namelist[1]
		else:
		    fname = thename

		print 'first name ',fname
		print 'last name ',lname
		user = User(
		    user_id=facebook.user_id, friends=friendsstr, 
		    access_token=facebook.access_token, name=me[u'name'],
		    first_name = fname, last_name = lname,
		    email=me.get(u'email'), picture=me[u'picture'])
		user.save()

	    except KeyError, ex:
		pass # ignore if can't get the minimum fields
Ejemplo n.º 3
0
def init_facebook(request):
    """Sets up the request specific Facebook and User instance"""
    facebook = Facebook()
    user = None
    friendslist = {}
    randomfriends = {}

    if u'signed_request' in request.POST:
        print 'POST request from FB with signed_request'
        facebook.load_signed_request(request.POST['signed_request'])
#request.META['REQUEST_METHOD'] = u'GET'
    elif 'u' in request.COOKIES:
        facebook.load_signed_request(request.COOKIES['u'])

    # try to load or create a user object
    # load from db and update access_token
    if facebook.user_id:
        try:
            user = User.objects.get(user_id=facebook.user_id)
        except User.DoesNotExist:
            pass
        if user:
            print 'User found in db'
            if facebook.access_token and \
             facebook.access_token != user.access_token:
                user.access_token = facebook.access_token
            user.save()
            if not facebook.access_token:
                facebook.access_token = user.access_token


#	    if user.dirty:
#	        user.refresh_data()
#get friendslist
            try:
                # me = {}
                me = facebook.api(u'/me', {u'fields': _USER_FIELDS})
                friends = [auser for auser in me[u'friends'][u'data']]
                i = 0
                for friend in friends:
                    uid = friend[u'id']
                    fn = friend[u'name']
                    frn = User(user_id=uid, first_name=fn)
                    friendslist[i] = frn
                    i = i + 1
                randomfriends = select_random(friendslist, 10)
            except KeyError, ex:
                pass  # ignore if can't get the minimum fields

            print 'printing user = '******'/me', {u'fields': _USER_FIELDS})
            try:
                # this should be a list of friends using this app
                friends = [auser for auser in me[u'friends'][u'data']]
                friendsstr = ','.join(
                    [user[u'id'] for user in me[u'friends'][u'data']])
                i = 0
                for friend in friends:
                    uid = friend[u'id']
                    fn = friend[u'name']
                    frn = User(user_id=uid, first_name=fn)
                    friendslist[i] = frn
                    i = i + 1
                randomfriends = select_random(friendslist, 10)
                thename = me[u'name']
                namelist = thename.split(' ')
                fname = ''
                lname = ''
                if (len(namelist)) > 1:
                    fname = namelist[0]
                    lname = namelist[1]
                else:
                    fname = thename

                print 'first name ', fname
                print 'last name ', lname
                user = User(user_id=facebook.user_id,
                            friends=friendsstr,
                            access_token=facebook.access_token,
                            name=me[u'name'],
                            first_name=fname,
                            last_name=lname,
                            email=me.get(u'email'),
                            picture=me[u'picture'])
                user.save()

            except KeyError, ex:
                pass  # ignore if can't get the minimum fields
Ejemplo n.º 4
0
    return params


################ MAIN ####################
# read paramters
path = sys.argv[0]
handle = sys.argv[1]
params_str = sys.argv[2]
params = read_params(params_str)

# read settings from settings.xml
get_settings()

if len(params) == 0:
    try:
        fb = Facebook(settings[API_KEY], settings[SECRET_KEY])

        # if there is no facebook session id
        if settings[SESSION_KEY] == "":
            # login for the first time
            facebook_login()
        else:
            # try to connect with the session id
            if not facebook_login_with_session():
                # if doesn't work - login with user & password to get a new session id
                facebook_login()

        show_news_feed()
    except FacebookError, (err):
        if err.code == "612":
            fb.request_extended_permission("read_stream")
Ejemplo n.º 5
0
                params[pair[0]] = pair[1]
            else:
                params[pair[0]] = True
    return params


################ MAIN ####################
# read paramters
path = sys.argv[0]
handle = sys.argv[1]
params_str = sys.argv[2]
params = read_params(params_str)

# read settings from settings.xml
get_settings()
fb = Facebook(settings[API_KEY], settings[SECRET_KEY])

# if there is no facebook session id
if (settings[SESSION_KEY] == ""):
    # login for the first time
    facebook_login()
else:
    # try to connect with the session id
    if (not facebook_login_with_session()):
        # if doesn't work - open browser login to get a new session id
        facebook_login()

if (len(params) == 0):
    show_main_menu()
else:
    if params.has_key("showAlbums"):