]> git.mxchange.org Git - friendica-addons.git/commitdiff
Improved timeout values/Posting local files
authorMichael <heluecht@pirati.ca>
Sat, 31 Mar 2018 18:55:17 +0000 (18:55 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 31 Mar 2018 18:55:17 +0000 (18:55 +0000)
twitter/twitter.php

index d82531f26e6c92bd5ee028bd036b1b8e671bb259..29a1a631adff61b2cf22332898e64cdb18e24219 100644 (file)
@@ -528,6 +528,9 @@ function twitter_post_hook(App $a, &$b)
 
                $connection = new TwitterOAuth($ckey, $csecret, $otoken, $osecret);
 
+               // Set the timeout for upload to 15 seconds
+               $connection->setTimeouts(10, 15);
+
                $max_char = 280;
                $msgarr = BBCode::toPlaintext($b, $max_char, true, 8);
                $msg = $msgarr["text"];
@@ -549,7 +552,14 @@ function twitter_post_hook(App $a, &$b)
                // and now tweet it :-)
                if (strlen($msg) && ($image != "")) {
                        try {
-                               $media = $connection->upload('media/upload', ['media' => $image]);
+                               $img_str = Network::fetchUrl($image);
+
+                               $tempfile = tempnam(get_temppath(), 'cache');
+                               file_put_contents($tempfile, $img_str);
+
+                               $media = $connection->upload('media/upload', ['media' => $tempfile]);
+
+                               unlink($tempfile);
 
                                $post = ['status' => $msg, 'media_ids' => $media->media_id_string];