Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python-oauth2 with Twitter's oauth_callback

I'm using Twython as my Twitter API wrapper, and oauth2 to handle authentication. I'm trying to have a use login via twitter, and then redirecting him after the oauth dance to a dynamically generated oauth_callback. This, however, appears to be impossible to do with these libraries straight out of the box. My problem is that my oauth client (python-oauth2), doesnt support callback urls. I find this very strange because this is the default oauth client used by Twython -- why would they bother writing code to accomodate the use of a dynamic callback and then bundle the library with an oauth client that doesn't support callbacks? Line 54 is set to false, therefore my callback url is never included in the request token url, as required in the oAuth 1.0a specs.

I've tried modifying both Twython and oauth2, but I keep running into problems. I'd like to know if there is an alternative to python-oauth2 that supports oauth_callback, or maybe an alternative twitter library that would handle the oauth properly.

like image 434
D-Nice Avatar asked Dec 28 '22 20:12

D-Nice


1 Answers

Found the answer here

All you have to do is pass Twython the parameter callback_url and replace line 205 in Twython.py with

resp, content = client.request(request_token_url, "POST",body=urllib.urlencode({'oauth_callback':my_callback_url}))

Notice, if you want twitter to respect your oauth_callback argument, the request must be a POST.

like image 179
D-Nice Avatar answered Dec 30 '22 11:12

D-Nice