Greetings
I use the following code in my app: www.referenciasocial.com
###############################
auth_user_id = (auth.user and auth.user.id) or None
Facebook = local_import('facebook')
#------ FACEBOOK ------
YOUR_CLIENT_ID = 'xxxxxxxxx'
YOUR_CLIENT_SECRET = 'xxxxx'
USERNAME = None
from gluon.contrib.login_methods.oauth20_account import OAuthAccount
class FaceBookAccount(OAuthAccount):
#OAuth impl for Facebook
AUTH_URL="https://graph.facebook.com/oauth/authorize"
TOKEN_URL="https://graph.facebook.com/oauth/access_token"
def __init__(self, g):
OAuthAccount.__init__(self, g,
YOUR_CLIENT_ID,
YOUR_CLIENT_SECRET,
self.AUTH_URL,
self.TOKEN_URL)
self.graph = None
# override function that fetches user info
def get_user(self):
"Returns the user using the Graph API"
if not self.accessToken():
return None
if not self.graph:
self.graph = Facebook.GraphAPI((self.accessToken()))
try:
user = self.graph.get_object("me")
return dict(first_name = user['first_name'],
last_name = user['last_name'],
username = user['id'],
link=user['link'])
except:
self.session.token = None
self.graph = None
return None
def data_login(id):
if auth.has_membership(user_id=id, role=my_group_default) is False:
auth.add_membership(user_id=id, role=my_group_default)
return None
auth.settings.login_form=FaceBookAccount(globals())
auth.settings.everybody_group_id = auth.id_group(my_group_default)
auth.settings.login_onaccept = lambda auth_user_id: data_login(auth_user_id)
auth.messages.logged_in=None
auth.messages.logged_out=None
###########
El jueves, 18 de septiembre de 2014 21:14:51 UTC-4:30, LoveWeb2py escribió:
>
> Using the default facebook appliance found here:
> https://github.com/mdipierro/web2py-appliances/tree/master/FacebookExample
>
> I setup a facebook application and put in my secret key and api. It
> successfully logs me in but for some reason it doesn't redirect back to my
> home page. You can try it out here if you'd like.
> http://ataylorusaf.pythonanywhere.com/facebook
>
> Here is my controller:
>
> from applications.facebook.modules.facebook import *
>
> facebook_settings.FACEBOOK_API_KEY = 'xxxxxxxxxx'
> facebook_settings.FACEBOOK_SECRET_KEY = 'xxxxxxx'
> facebook_settings.FACEBOOK_APP_NAME = "Synthetic Turf Doctors"
> facebook_settings.FACEBOOK_INTERNAL = True
> facebook_settings.FACEBOOK_CALLBACK_PATH = "/facebook/default/index"
>
> def index():
> require_facebook_login(request,facebook_settings)
> return dict(message="Hello "+get_facebook_user(request))
>
> Once it logs me in, I'm never returned to the index page. Instead my url
> changes to: https://www.facebook.com/desktopapp.php#_=_
>
> any thoughts on why this is happening? I've tried reading up on the
> facebook class and the callback path should redirect me to my index if I'm
> reading it properly. Appreciate any help
>
>
>
>
>
>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.