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

Didn´t understand how to upload an image!

Open ArthurBugan opened this issue 7 years ago • 6 comments

I'm trying to upload an image but i see that the example code sugests: // these files to upload. You can also just upload 1 image! $media_files = [ 'bird1.jpg', 'bird2.jpg', 'bird3.jpg' ];

// will hold the uploaded IDs $media_ids = [];

foreach ($media_files as $file) { // upload all media files $reply = $cb->media_upload([ 'media' => $file ]); // and collect their IDs $media_ids[] = $reply->media_id_string; }

Where should this 'bird1.jpg', 'bird2.jpg', 'bird3.jpg' be located? I'm trying to upload but i tried to pass and image and i receive Request error for API call: Operation timed out after 10000 milliseconds with 0 bytes received.

I tried to upload just a simple tweet and didnt have any problem, thanks!

ArthurBugan avatar Jun 05 '17 06:06 ArthurBugan

The files mentioned in the README should be in your local working directory (find out with echo getcwd();. If you would like to load images from different paths, use a relative or an absolute local path on your server. By the way, remote images will work as well, if they can be reached authorisation-free at a http or https URL.

Does this help you?

mynetx avatar Jun 07 '17 19:06 mynetx

Thanks for the reply, but I think that i'm having some problem with my IP being blocked by twitter. Here is my code:

public function uploadImages($images){      
        //Pega o nome de todos os arquivos para passar para o twitter
        //Get the name of all files and upload them
        foreach ($images as $image){
            $media_files[] = $image['arquivo'];
        }

        $media_ids = [];

        foreach ($media_files as $file) {
            $imagedata = (getcwd().'\\anexos\\'.$file);

            $reply =  $this->twitter->media_upload(array(
                'media' => $imagedata
            ));

            // and collect their IDs
            //$media_ids[] = $reply->media_id_string;
            var_dump($reply);
            exit();
        }

        return $media_ids;
    }

The value of $imagedata = "C:\Users\Arthur\Documents\imobweb\public\anexos\anexo_9a3f72ba.jpg" Still getting: Request error for API call: Operation timed out after 10015 milliseconds with 0 bytes received

ArthurBugan avatar Jun 08 '17 06:06 ArthurBugan

Okay, which PHP and Windows version are you working on, and could you please send us a sample image of that for our testing? If you don't want to post it in public, send it to [email protected].

mynetx avatar Jun 08 '17 10:06 mynetx

I'm running windows 7 64bits and my php version is 5.6.28 anexo_61361e6f

ArthurBugan avatar Jun 08 '17 10:06 ArthurBugan

I manage to get it working using a URL, but if i try to use a url from my site it doesnt upload the image, but if I try with a google images url it works. Here is my image: http://cartaobenefacil.com.br/anexos/anexo01d9f82d.jpg Could you try with this?

ArthurBugan avatar Jun 12 '17 18:06 ArthurBugan

Is your server reachable by itself? That is, can PHP request URLs from its own server? Have you tried using a local path?

mynetx avatar Jun 12 '17 20:06 mynetx