Overriding Twitter’s Default Callback Url using Oauth
Unlike Facebook, Twitter does not let you specifiy your callback url when you are initiating Twitter’s Oauth procedure. The default Callback Url is the one specified when you registered your application here https://dev.twitter.com/apps/new . If you wanted to change your callback url, you would have to manually log in to your app settings in https://dev.twitter.com/apps and edit them. This is annoying for various reasons.Suppose you have a single twitter application, that you want to use on multiple sites. For example, let us say Groupon, has two sites. One for its customers and one for its clients,customer.groupon.com and clients.groupon.com. When a customer clicks on ‘Connect to Twitter’ in the customer website, let’s say it uses the default callback url in the twitter website, customer.groupon.com. But when a client clicks the ‘Connect to Twitter’ to link the clients account with twitter, so it can tweet new deals everytime it makes a deal on groupon, the default callback needs to be overriden so it becomes clients.groupon.com instead of customer.groupon.com.
Turns out the default callback url can be overriden very easily, though not straighforward at first.
If you wanted to use the default callback url, you just send a HTTP GET request to ’http://twitter.com/oauth/request_token’ and ‘http://twitter.com/oauth/access_token’.
If you wanted to override the default callback URL, you would send a HTTP POST request to the request token url and access token url with
body= urllib.urlencode(‘oauth_callback’:’site-you-want-to-redirect-to’).
Now, you can override, twitter’s default callback url, depending on which site you are using your ‘Connect to Twitter’ feature.