this should be the correct way to access the user access token.
token = auth.settings.login_form.accessToken()

2014-05-14 6:51 GMT+02:00 EvilLinux <evilli...@gmail.com>:
> Hello,
>
> I am hoping someone might be able to help me figure what I might be doing
> wrong or what the next steps I would need to do with calling the user's
> facebook access token.  I followed the web2py book's method to obtain the
> facebook login:
>
> ## import required modules
> try:
>     import json
> except ImportError:
>     from gluon.contrib import simplejson as json
> from facebook import GraphAPI, GraphAPIError
> from gluon.contrib.login_methods.oauth20_account import OAuthAccount
>
>
> ## extend the OAUthAccount class
> 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):
>         OAuthAccount.__init__(self, None, FB_CLIENT_ID, FB_CLIENT_SECRET,
>                               self.AUTH_URL, self.TOKEN_URL,
>                               scope='email, publish_actions',
>                               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' %(email) )
>
> ## use the above class to build a new login form
> auth.settings.login_form=FaceBookAccount()
>
> So I am able to successfully login and log out without any issues with the
> system which is great.  The problem I am running into is I do not understand
> where it stores and/or how to access the user's FB token so I am able to
> allow them to click a link or submit a form and have it posted to their
> wall.
>
> I looked through the examples of the facebook-sdk:
> https://github.com/pythonforfacebook/facebook-sdk and it seems really simple
> that I would just need to do what the front page says.  I am able to do that
> if I go a hardcode an access token in which I do not believe is the proper
> method when you want to have different users be able to post to their own
> walls correct?
>
> Thank you in advance for any direction or sample code that may be provided I
> greatly appreciate it.
>
> --
> 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 web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to