Hello Thanks for the note. I was using the Simple Authentication on my application to send tweets. I just noticed that twitter no longer support it. I guess I have to switch to Twitter oAuth API. I was wondering because it looks like to send tweet, each user of my application should get a CLIENT_ID, CLIENT_SECRET (oauth_token and oauth_token_secret). I wonder where they will get it from ? Should each of them have to register my application in their twitter Account to get it ?
Thanks for your help, Yannick P. On Aug 30, 4:00 am, Michele Comitini <[email protected]> wrote: > Actually if you look on developer.twitter.com, you will find some > library that maps thetwitterREST api to > python methods. But I did not relay on that as it would have added > more dependencies. > I think that is something that you can use depending the application > you are going to develop. > > Things are simple even without external libraries, look for instance > at the get_user method in db.py, how it gets user > info:http://code.google.com/r/michelecomitini-facebookaccess/source/browse... > > def get_user(self): > if self.accessToken() is not None: > client =oauth.Client(self.consumer, self.accessToken()) > resp, content = > client.request('http://api.twitter.com/1/account/verify_credentials.json') > if resp['status'] != '200': > # cannot get user info. should check status > return None > u = json.loads(content) > return dict(username=u['screen_name'], name=u['name'], > registration_id=u['id']) > > so you build a client, make a request to a REST api url > (http://api.twitter.com/1/account/verify_credentials.json) > > To post a tweet see:http://dev.twitter.com/doc/post/statuses/update > > in your controller you should write something like this: > > import oauth2 asoauth > . > . > . > @auth.requires_login() > def sendtweet(): > token = auth.settings.login_form.accessToken() # you can use this > also if you prefer: token=session.access_token > consumer =oauth.Consumer(CLIENT_ID, CLIENT_SECRET) #<- CLIENT_ID, > CLIENT_SECRET are defined in db.py > client =oauth.Client(self.consumer, token) > # encode the message > message = 'My web2py post!" > data=urlencode(status=message) > #make a post > resp, content = > client.request('http://api.twitter.com/1/statuses/update.json', > "POST", body=data) > if resp['status'] != '200': > #manage the error > return dict(message="Could not send tweet! :-( ") > > return dict(message="Succesfully sent! :-)") > > if you call method returning some data I suggest tu use the .json > version of it and use > simplejson to decode it to a python dictionary (see the get_user() method > above) > > hope that helps... > mic > > 2010/8/30 Albert Abril <[email protected]>: > > > Just a question: what do you use for post a tweet, read statuses... ? > > Thanks in advance. > > > On Sun, Aug 29, 2010 at 12:39 PM, Albert Abril <[email protected]> > > wrote: > > >> :) Thank you! > > >> On Sun, Aug 29, 2010 at 1:45 AM, Michele Comitini > >> <[email protected]> wrote: > > >>> Hello all, > > >>> I've uploaded a scaffolding app as example of authentication with > >>>twitteroauth. You can find source code here: > > >>>https://code.google.com/r/michelecomitini-facebookaccess/source/brows... > > >>> Or you can clone the repository locally: > >>>https://code.google.com/r/michelecomitini-facebookaccess/source/checkout > > >>> as usual it is also on GAE for testing: > >>>http://grafbook.appspot.com/helloTwitter > > >>> Please enjoy and send feedback. > > >>> tnx > >>> michele

