codebird-php icon indicating copy to clipboard operation
codebird-php copied to clipboard

How to retrieve image from direct messages and upload it as tweet directly?

Open twnku opened this issue 5 years ago • 0 comments

ive retrieve a image url from direct messages using this

$parameter_get_dm = ['count' => 10];
$get_dm = $twitter->directMessages_events_list($parameter_get_dm);
foreach($get_dm->events as $item){
$file = $item->message_create->message_data->attachment->media->media_url;
}

it will show https://ton.twitter.com/i/ton/data/dm/123/123/filename.jpg after

then i use this to upload the media

$upldimg = $twitter->media_upload([
 'media' => 'https://ton.twitter.com/1.1/ton/data/dm/123/123/filename.jpg'
 ]);
 print_r($upldimg);

but it is not working and the error log shows

[06-May-2020 14:10:39 UTC] PHP Fatal error:  Uncaught Codebird\CodebirdMediaException: Downloading a remote media file failed. in .../vendor/codebird/src/codebird.php:1924
Stack trace:
#0 .../vendor/codebird/src/codebird.php(1886): Codebird\Codebird->_fetchRemoteFile('https://ton.twi...')
#1 .../vendor/codebird/src/codebird.php(1826): Codebird\Codebird->_buildBinaryBody('https://ton.twi...')
#2 .../vendor/codebird/src/codebird.php(1800): Codebird\Codebird->_checkForFiles('media/upload', 'media', 'https://ton.twi...')
#3 .../vendor/codebird/src/codebird.php(1858): Codebird\Codebird->_getMultipartRequestFromParams('media/upload', '---------------...', Array)
#4 .../vendor/codebird/src/codebird.php(2263): Codebird\Codebird->_buildMultipart('media/upload', Array)
#5 /h in .../vendor/codebird/src/codebird.php on line 1924

how to solve this? iam still confused using this library

twnku avatar May 06 '20 14:05 twnku