It uploads the text to Daily BirdBreath without the image with no error messages.
I would greatly appreciate any help or advice you can give me.
Thanks Robert
Here’s the code.
?php
// include config and twitter api wrapper //
require_once( 'TwitterAPIExchange.php' );
$date = date("Ymd");
//echo "$date\n";
$star = "*";
$png = ".png";
#Check if it exists
if (file_exists($filename_current)) {
$file_current = system("ls ../complete/midphase/$date$star$png");
echo "file exists\n";
echo "$file_current\n";
}else{
$file_current = system("ls ../complete/midphase/$date$png");
echo "this file exists\n";
echo "$file_current\n";
}*(*/
$file_current = '/Users/robertseymour/MacBook_Local/complete/midphase/t.png';
echo "$file_current\n\n";
// settings for twitter api connection//
/** Set access tokens here - see: https://dev.twitter.com/apps/ **/
$settings = array(
'oauth_access_token' =>
"50180715-...",
'oauth_access_token_secret' => "...",
'consumer_key' => "...",
'consumer_secret' => "...");
$twitter = new TwitterAPIExchange($settings);
$file = file_get_contents($file_current);
$data = base64_encode($file);
//echo "$data\n\n";;
// Upload image to twitter
$url = "https://upload.twitter.com/1.1/media/upload.json"; $method = "POST"; $params = array("media_data" => $data);
$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.' );
print_r($postfields);
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] => 1616927890947596288
[status] => Heres your new weekday BirdBreath cartoon http://birdbreath.com #parrot #bird #cartoon.
)
echo $twitter->buildOauth($url, $method)->setPostfields($postfields)->performRequest();
system
Closed
#2
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.