Reputation: 7013
So I have setup a twitter application so that people can reply to tweets inside my own app. I have a callback URL and when I do not try and override it everything seems to go fine. However Now I am having a problem getting the override of the callback to work the app runs on multiple sub domains and servers based on what stage of development it is in and I would like to override the callback to the current url.
When I do override the callback and twitter attempts to send the User back to that page I get to a page that says "Sorry, that page doesn’t exist!"
and the URL looks something like this
and Here is my Python code using this library for the oauth: https://github.com/simplegeo/python-oauth2
#SETUP TWITTER AUTHORIZATION OBJECT
request_token_url = 'http://twitter.com/oauth/request_token'
access_token_url = 'http://twitter.com/oauth/access_token'
authorize_url = 'http://twitter.com/oauth/authenticate'
consumer = oauth.Consumer(consumer_key, consumer_secret)
client = oauth.Client(consumer)
#get request token
callbackURL = urllib.quote("%s?twitterCallback" % self.request.url)
resp, content = client.request(request_token_url, "POST", body=urllib.urlencode({'oauth_callback':callbackURL}))
if resp['status'] != '200':
raise Exception("Invalid Response %s." %resp['status'])
request_token = dict(urlparse.parse_qsl(content))
tmpldict['callbackURL'] = callbackURL
tmpldict['oauth_token'] = request_token['oauth_token']
tmpldict['twitauthurl'] = "%s?oauth_token=%s" % ( authorize_url, request_token['oauth_token'] )
qargs=urlparse_qs(self.request.url,True,False)
if 'oauth_verifier' in qargs:
oauth_verifier = qargs['oauth_verifier'][0]
else:
oauth_verifier = None
if oauth_verifier:
token = oauth.Token(request_token['oauth_token'], request_token['oauth_token_secret'])
token.set_verifier(oauth_verifier)
client = oauth.Client(consumer,token)
resp, content = client.request(access_token_url, "GET")
access_token = dict(urlparse.parse_qsl(content))
Current Flow for User
Click authorization URL
Hit Allow Access on Twitter
Twitter Displays: Redirecting you back to the application
Cannot Find page with URL like the example above.
Upvotes: 0
Views: 1124
Reputation: 2296
Few quick things...
Your URLs are old and outdated and don't function as well as the proper URLs. Use SSL and the api subdomain:
It's unclear to me looking at this code whether you're performing header-based OAuth or querystring-based OAuth. I recommend header-based OAuth -- it dramatically separates concerns and makes it easier to discover wrongness when it happens.
Make sure that when you send your dynamic oauth_callback value to the oauth/request_token step that it's correctly percent-encoded. Also, make sure you have a placeholder HTTP-based callback on your application record on dev.twitter.com/apps
Upvotes: 4