web2py book standalone facebook login doesn't work.

36 views
Skip to first unread message

guruyaya

unread,
Sep 21, 2013, 1:00:18 AM9/21/13
to web2py-d...@googlegroups.com
It doesn't even make sense, as the facebook object init function needs a variable called g, that it doesn't use use in the inital call. I've filling in the g with None, I can get the login to direct me to facebook and back, but it's not registering my user (I see no change in the auth_user table). Any chance someone can make a quick fix for this one, because I'm kinda lost at this point

Michele Comitini

unread,
Sep 22, 2013, 10:05:19 AM9/22/13
to web2py-developers
The g argument is due to backward compatibility to when the globals() needed to be passed explicitly in web2py since there was no gluon.current. The following is a shorter version of what I use in production.

HTH

mic

--------

from facebook import GraphAPI, GraphAPIError
from gluon.contrib.login_methods.oauth20_account import OAuthAccount

try:
    import json
except ImportError:
    from gluon.contrib import simplejson as json

FB_CLIENT_ID='xxx'
FB_CLIENT_SECRET="yyyy"
class FaceBookAccount(OAuthAccount):
    """OAuth impl for FaceBook"""

    def __init__(self):
        OAuthAccount.__init__(self, None, FB_CLIENT_ID, FB_CLIENT_SECRET,
                              self.AUTH_URL, self.TOKEN_URL,
                              scope='email,user_about_me,user_activities, user_birthday, user_education_history, user_groups, user_hometown, user_interests, user_likes, user_location, user_relationships, user_relationship_details, user_religion_politics, user_subscriptions, user_work_history, user_photos, user_status, user_videos, publish_actions, friends_hometown, friends_location,friends_photos',
                              state="auth_provider=facebook",
                              display='popup')
        self.graph = None

    def get_user(self):
        '''Returns the user using the Graph API.
        '''
        if not self.accessToken():
            return None

        if not self.graph:
            self.graph = GraphAPI((self.accessToken()))

        user = None
        try:
            user = self.graph.get_object("me")
        except GraphAPIError, e:
            session.token = None
            self.graph = None

        if user:
            if not user.has_key('username'):
                username = user['id']
            else:
                username = user['username']
                
            if not user.has_key('email'):
                email = '%s.fakemail' %(user['id'])
            else:
                email = user['email']    

            return dict(first_name = user['first_name'],
                        last_name = user['last_name'],
                        username = username,
                        email = '%s.%s' %(email) )

guruyaya

unread,
Sep 24, 2013, 5:02:43 PM9/24/13
to web2py-d...@googlegroups.com
This one worked. after I've replaced 
 email = '%s.%s' %(email) )
with 
 email = '%s' %(email) )
(I have no idea why the extra %s is there).
Thanks

Michele Comitini

unread,
Sep 24, 2013, 5:05:45 PM9/24/13
to web2py-developers
my bad I did a cleanup and forgot the %s ;-)


2013/9/24 guruyaya <guru...@gmail.com>

--
-- mail from:GoogleGroups "web2py-developers" mailing list
make speech: web2py-d...@googlegroups.com
unsubscribe: web2py-develop...@googlegroups.com
details : http://groups.google.com/group/web2py-developers
the project: http://code.google.com/p/web2py/
official : http://www.web2py.com/
---
You received this message because you are subscribed to the Google Groups "web2py-developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py-develop...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages