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.
I have the same problem on my web site. It just stopped working.
Where do I have to copy/paste this new line of code? Within my module, the code seems to be splitted over 2 files: OAuth.php and twitteroauth.php
Any help would be greatly appreciated!
I forgot to mention: I’m using a Joomla! CMS. Don’t think it makes a difference, but just in case.
Oh well… looks like my first post did not go through. I was asking where I should add this new code you are referring to. I checked my clock settings and it looks fine.
Within my Joomla module, I have 2 files: OAuth.php and twitteroauth.php.
Thanks for any help you an provide!
I’m not using PHP, but you need to set the request header “User-Agent” in your call to Twitter.
Oh, and still keep an eye on your server time stamp. That causes problems for many people.
PS I approve all comments manually to avoid spam, that’s why your original comment didn’t appear.
Thaks! Whole day I was looking for solution.Finally this torture ended.
What’s wrong with twitter deveopers?