from gluon.contrib.login_methods.oauth10a_account import OAuthAccount
from oauth2 import Client, Consumer, Token
 
import gluon.contrib.simplejson as json

class TwitterAccount(OAuthAccount):
    AUTH_URL = "https://api.twitter.com/oauth/authorize";
    TOKEN_URL = "https://api.twitter.com/oauth/request_token";
    ACCESS_TOKEN_URL = "https://api.twitter.com/oauth/access_token";
    CLIENT_ID = "xxxxxxxxx"
    CLIENT_SECRET = "xxxxxxxx"
 
    def __init__(self, g):
        OAuthAccount.__init__(self, g,
                              self.CLIENT_ID,
                              self.CLIENT_SECRET,
                              self.AUTH_URL,
                              self.TOKEN_URL,
                              self.ACCESS_TOKEN_URL)
 
    def get_user(self): 
        if self.accessToken():
            consumer = Consumer(key=self.CLIENT_ID,  
secret=self.CLIENT_SECRET)
            print consumer
            client = Client(consumer, self.accessToken())
            resp, content = 
client.request('https://api.twitter.com/1.1/account/verify_credentials.json')
            print resp
            print content
            if resp['status'] != '200':
                # cannot get user info. should check status
                return None
            u = json.loads(content)
            print u
            return dict(first_name = u['name'], username=u['screen_name'],
                  name=u['name'], registration_id=u['id'])
 
auth.settings.actions_disabled=['register','change_password','request_reset_password','profile']
auth.settings.login_form=TwitterAccount(g=globals())
auth.settings.login_next = URL('default','index')
--------
 They give the example found error loop as update the twitter api
old:
resp, content = client.request ('
http://api.twitter.com/1/account/verify_credentials.json')
new:
resp, content = client.request ('
https://api.twitter.com/1.1/account/verify_credentials.json')

-- 
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.

Reply via email to