Closed protoss5482 closed 7 years ago
Can you post the simple code you're using to make the request?
$message_post = "Text #hash";
$settings = array(
'oauth_access_token' => "AAAAA",
'oauth_access_token_secret' => "BBBBB",
'consumer_key' => "CCCCC",
'consumer_secret' => "DDDDD"
);
$twitter = new TwitterAPIExchange($settings);
$file = file_get_contents($itempost["image_url"]);
$data = base64_encode($file);
$url = 'https://upload.twitter.com/1.1/media/upload.json';
$method = 'POST';
$params = array(
'media_data' => $data
);
$data = $twitter->request($url, $method, $params);
$data = @json_decode($data, true);
$mediaId = $data['media_id'];
$url = 'https://api.twitter.com/1.1/statuses/update.json';
$method = 'POST';
$params = array(
'status' => $message_post,
'possibly_sensitive' => false,
'media_ids' => $mediaId
);
$data = $twitter->request($url, $method, $params);
Example data perfect work:
Attach file: image_url: /var/www/crazypicture.tk/public_html/files/images/gif_1472587865.4758.gif -rw-r--r-- 1 www-data www-data 1021658 Aug 30 23:11 gif_1472587865.4758.gif can see: http://crazypicture.tk/files/images/gif_1472587865.4758.gif
Tweet Text:
http://crazypicture.tk/image.php?id=3128
Smoko #Drunk
More #funny #gifs in the #Android https://play.google.com/store/apps/details?id=ua.protoss5482.crazypicture
result: https://twitter.com/CrazyPictureMem/status/773961379808247809
Example Not work:
Attach file: image_url: /var/www/crazypicture.tk/public_html/files/images/gif_1472587713.52.gif -rw-r--r-- 1 www-data www-data 2876558 Aug 30 23:08 gif_1472587713.52.gif can see: http://crazypicture.tk/files/images/gif_1472587713.52.gif
Tweet Text:
http://crazypicture.tk/image.php?id=3129
Trick
More #funny #gifs in the #Android https://play.google.com/store/apps/details?id=ua.protoss5482.crazypicture
result: TwitterAPIExchange.php on line 305
In-between making requests, can you try making a new \TwitterApiExchange
object? As in, don't re-use the object, re-create it?
I found a solution! The picture did not have time to go in 10 seconds. I set a timeout of 30 seconds, and it worked.
$options = array( CURLOPT_HTTPHEADER => $header, CURLOPT_HEADER => false, CURLOPT_URL => $this->url, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 30, ) + $curlOptions;
Fatal error: Uncaught Exception: Operation timed out after 10000 milliseconds with 0 bytes received in XXXXX/public_html/api_social/twitter/TwitterAPIExchange.php:305 Stack trace:
0 XXXXX/public_html/api_social/twitter/TwitterAPIExchange.php(382): TwitterAPIExchange->performRequest(true, Array)
1 XXXXX/public_html/api_social/twitter/twitter_autopost_en.php(97): TwitterAPIExchange->request('https://upload....', 'POST', Array)
2 {main}
thrown in XXXXX/public_html/api_social/twitter/TwitterAPIExchange.php on line 305