More Twitter API Shenanigans

Since Elon Musk took over Twitter things have been, how can I put this politely, a little unstable. Then, last Friday, the platform started to limit the number of Tweets that you can view. At the same time that this change was implemented my calls to the API stopped working returning the following:

stdClass Object (
   [errors] => Array (
      [0] => stdClass Object (
         [message] => Sorry, that page does not exist
         [code] => 34
      )
   )
) 

Searching online turned up nothing much about this specifc error message and nothing recent either. I spent a bit of time tinkering with my code checking and rechecking it for any potential issues even though this was unlikely as I hadn’t changed it for a while. What was a bit odd was that creating Tweets would work from my local server but not in production.

In the end I decided to post a message to the github page of the library I use to post to Twitter, TwitterOAuth, and a couple of other people responded that they had too had noticed a similar thing and that for them too it would work locally and not in production. What was also curious was that one other person was also on Linode.

What seems to have happened is that along with limiting Tweet reads a number of IP addresses have also been blocked including those from Linode. It would be lovely if we could persuade Twitter that our addresses were benign but that was going to take time. The answer, therefore, was to route the calls via a proxy.

This required getting access to a proxy which, fortunately, someone had recommended Webshare so I duly signed up and grabbed the required details. Once I had my proxy details a change was needed to the TwitterOauth code to force it to use it. This was made in ./vendor/abraham/twitteroauth/src/TwitterOAuth.php as follows:

// line 650 aprox
private function request(...) {
...
...
        $options[CURLOPT_PROXY] = 'nnn.nnn.nnn.nnn';
        $options[CURLOPT_PROXYPORT] = 'nnnn';
        $options[CURLOPT_PROXYUSERPWD] = 'username:password';
}

This brought the ability to Tweet back online but I am left wondering what Musk has up his sleeve for me next in my ongoing battle with the Twitter API.

Leave a Reply

Your email address will not be published. Required fields are marked *