<?php
// include config and twitter api wrapper //
require_once( 'TwitterAPIExchange.php' );
$date = date("Ymd");
echo "$date\n";
$star = "*";
$a = "a";
$png = ".png";
$file = "$date$star$png";
$file_current = system("ls /Users/robertseymour/MacBook_Local/complete/midphase/$file");
// settings for twitter api connection//
/** Set access tokens here - see: https://dev.twitter.com/apps/ **/
$settings = array(
'oauth_access_token' =>
"50180715-3F7yZmwBLJouO3fa6avhW0AJG0d7Y9bfMpRWYQEkQ",
'oauth_access_token_secret' => "tLatm320LcRYh5ti4LV4iMk3eiE0zyI691XeXA71is",
'consumer_key' => "TcrdUlDdg8id1ZYjdXg",
'consumer_secret' => "CfdKClaUYtG4caUU55q7InwsYYjJH8h3u0vRhY5I");
$file = file_get_contents($file_current);
$data = base64_encode($file);
$twitter = new TwitterAPIExchange($settings);
// Upload image to twitter//
$url = "https://upload.twitter.com/1.1/media/upload.json";
$method = "POST";
$params = array(
"media_data" => $data);
//echo "$url\n";//
//echo "$method\n";//
$twitter->buildOauth($url, $method);
$json = $twitter
->buildOauth($url, $method)
->setPostfields($params)
->performRequest();
// Result is a json string//
$res = json_decode($json);
// Extract media id
$id = $res->media_id_string;
$url = 'https://api.twitter.com/1.1/statuses/update.json';
$method = 'POST';
$postfields = array(
'media_ids' => $id,
'status' => 'Heres your new weekday BirdBreath cartoon http://birdbreath.com #parrot #bird #cartoon.' );
if(strlen($postfields['status']) <= 140)
{
$twitter = new TwitterAPIExchange($settings);
$twitter->buildOauth($url, $method)
->setPostfields($postfields)
->performRequest();
}else{
echo "140 char exceed";
}
print_r($postfields);
Array ( [media_ids] => 1615104943115075584 [status] => Heres your new weekday BirdBreath cartoon http://birdbreath.com #parrot #bird #cartoon. )
This script no longer uploads the image. It does however upload the text to Daily BirdBreath.Any idea why? Do you see any errors? It worked prior to January 5th this year. Is API vi.1 still supported?
I would greatly appreciate any help or advice you can give me.
Thanks Robert