TweetWX script updated for Twitter API V1.1

Got to love the Twitter developers … they turned off the API V1.0 on 11-June-2013 and forced everyone to use the API V1.1 instead.

Sigh… I’ve done an update to TweetWX-globals.php that should fix your issues (no customization needed). The changes are to use HTTPS/SSL instead of HTTP for posting the status (and a new destination URL).

Let me know how it works for you :slight_smile:

Best regards,
Ken


TweetWX-globals.php.txt (15.9 KB)

For those who would prefer to update their code in-place, the following changes were made to TweetWX-global.php (also applies to Mike’s TweetWX642-global.php script):

Change:

function do_post($url, $postbody, $port=80, $headers=NULL)
{
  $retarr = array();  // Return value

  $curl_opts = array(CURLOPT_URL => $url,
                     CURLOPT_PORT => $port,
                     CURLOPT_POST => true,
                     CURLOPT_SSL_VERIFYHOST => false,
                     CURLOPT_SSL_VERIFYPEER => false,
                     CURLOPT_POSTFIELDS => $postbody,
                     CURLOPT_RETURNTRANSFER => true);

To:

function do_post($url, $postbody, $port=443, $headers=NULL)
{
  $retarr = array();  // Return value

  $curl_opts = array(CURLOPT_URL => $url,
                     CURLOPT_PORT => $port,
                     CURLOPT_POST => true,
                     CURLOPT_SSL_VERIFYHOST => true,
                     CURLOPT_SSL_VERIFYPEER => true,
                     CURLOPT_POSTFIELDS => $postbody,
                     CURLOPT_RETURNTRANSFER => true);

Change:

  $url = 'http://api.twitter.com/1/statuses/update.json';

To:

  $url = 'https://api.twitter.com/1.1/statuses/update.json';

Change:

  if ($usePost) {
    $request_url = $url;
    logit("tweet:INFO:request_url:$request_url");
    logit("tweet:INFO:post_body:$query_parameter_string");
    $headers[] = 'Content-Type: application/x-www-form-urlencoded';
    $response = do_post($request_url, $query_parameter_string, 80, $headers);
  } else {

To:

  if ($usePost) {
    $request_url = $url;
    logit("tweet:INFO:request_url:$request_url");
    logit("tweet:INFO:post_body:$query_parameter_string");
    $headers[] = 'Content-Type: application/x-www-form-urlencoded';
    $response = do_post($request_url, $query_parameter_string, 443, $headers);
  } else {

And your feed should work again.

Best regards,
Ken

Using this script to generate an hourly Tweet @Selstonweather. Got it working in less than an hour, which is good for my 60 year old brain. Tomorrow, I’ll try to set up an end of day summary and change the times to 24 hour format. Anyone want to give me some clues while I get some sleep?

Thanks Ken. Your fix worked great.

Ken, Thanks for the updated code.

I updated my scripts

TweetWX scripts no longer function after 12:00 13-Jun-2023 Pacific. Twitter has suspended the application ID for TweetWX for ‘rules violations’ (likely over 1500 tweets per month with all the instances sharing the same app ID).
Sigh… I’ve now deprecated the scripts and suggest you take them off your cron executions.

Modify message

1 Like

They blocked my weather-display automated account. Was only doing hourly updates. Cannot get a response from email.

Posting to Mastodon using a script 4 times a day for each station