cloudy cloudy

Author Topic: TweetWX script updated for Twitter API V1.1  (Read 1324 times)

0 Members and 1 Guest are viewing this topic.

Offline saratogaWX

  • Global Moderator
  • Posts: 5,945
  • Ken True
  • Saratoga, CA, USA 37:16:28N, 122:01:23W - Elev: 374ft.
  • OS/Browser:
  • Win 7/Srvr 2008R2
  • Firefox 21.0
    • Saratoga Weather
TweetWX script updated for Twitter API V1.1
« on: June 13, 2013, 06:08:43 PM »
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 :)

Best regards,
Ken
Ken True
Saratoga Weather
CWOP: CW1792
WeatherUnderground: KCASARAT1
Free weather website PHP scripts and WD website AJAX templates

Offline saratogaWX

  • Global Moderator
  • Posts: 5,945
  • Ken True
  • Saratoga, CA, USA 37:16:28N, 122:01:23W - Elev: 374ft.
  • OS/Browser:
  • Win 7/Srvr 2008R2
  • Firefox 21.0
    • Saratoga Weather
Re: TweetWX script updated for Twitter API V1.1
« Reply #1 on: June 13, 2013, 09:27:06 PM »
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:
Code: [Select]
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:
Code: [Select]
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:
Code: [Select]
  $url = 'http://api.twitter.com/1/statuses/update.json';

To:
Code: [Select]
  $url = 'https://api.twitter.com/1.1/statuses/update.json';

Change:
Code: [Select]
  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:
Code: [Select]
  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
Ken True
Saratoga Weather
CWOP: CW1792
WeatherUnderground: KCASARAT1
Free weather website PHP scripts and WD website AJAX templates

Offline Alan Rowley

  • Posts: 405
  • Selston, Nottinghamshire, England
    • Bracken House Weather
Re: TweetWX script updated for Twitter API V1.1
« Reply #2 on: June 13, 2013, 10:21:25 PM »
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?


Sent from my iPad using Tapatalk

Offline ALITTLEweird1

  • Mark
  • Global Moderator
  • Posts: 5,155
  • North Bend, WA
  • OS/Browser:
  • Win 7/Srvr 2008R2
  • MS IE 10.0
    • North Bend Weather
Re: TweetWX script updated for Twitter API V1.1
« Reply #3 on: June 14, 2013, 02:29:00 AM »
Thanks Ken. Your fix worked great.
"Nature can do without man, but man cannot do without nature."

Davis VP2 + VP2 Solar + VP2 UV + Lightning Detector + Logitech Webcam

Offline MCHALLIS

  • Posts: 2,158
  • Long Beach, WA USA
  • OS/Browser:
  • Win 7/Srvr 2008R2
  • Firefox 21.0
    • Weather for Long Beach, WA USA
Re: TweetWX script updated for Twitter API V1.1
« Reply #4 on: June 17, 2013, 03:27:50 AM »
Ken, Thanks for the updated code.

I updated my scripts