Part of the fun of being a developer is keeping up with the advances, improvements and quirks in the APIs of the various online services you need to interact with. I spend a lot of time working with APIs from sites like Twitter, Facebook and SalesForce.
Late yesterday users on one of my sites started to report problems connecting their Twitter accounts, and posting to Twitter. The code on the site has been happily working for more than a year, so it felt to me something must have changed somewhere – and most likely at Twitter’s end. The error stated “There is no request token for this page”.
I traced the issue to the initial OAUTH call to request a token, the first step to actually issuing a full request to the Twitter API. After a little research online I discovered someone else had experienced exactly the same issue.
The solution is to specify a User-Agent in the POST, for example:
objXMLHTTP.SetRequestHeader "User-Agent", "something"
Note, this is exactly what I added – “something” seems to work fine. I’ve read that Twitter is continuing to tighten up access to their API, this issue only appeared yesterday for me, so clearly the Twitter devs have been tweaking things behind the scenes.
As a sidebar I was led up a small garden path for a short time. I tried pasting the request token URL directly into my browser and was rewarded with a message from Twitter “Failed to validate oauth signature and token”.
I played with this for a while before realising this error is almost always caused by the time clock on your server not being correct – remember, you are passing a time stamp as part of your URL, and Twitter checks that against its own internal time, if you are a little out of sync Twitter will reject the request. The time clock on my server is fine – and of course one then slaps ones forehead and realises that the time that elapsed between running your initial call, generating the URL, and pasting it into your browser is probably enough for Twitter to decide your time clock is wrong.