jublo / codebird-php

Easy access to the Twitter REST API, Direct Messages API, Account Activity API, TON (Object Nest) API and Twitter Ads API — all from one PHP library.
https://www.jublo.net/projects/codebird/php
GNU General Public License v3.0
777 stars 235 forks source link

Didn´t understand how to upload an image! #203

Closed ArthurBugan closed 1 year ago

ArthurBugan commented 7 years ago

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!

mynetx commented 7 years ago

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?

ArthurBugan commented 7 years ago

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

mynetx commented 7 years ago

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 support@jublo.net.

ArthurBugan commented 7 years ago

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

ArthurBugan commented 7 years ago

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?

mynetx commented 7 years ago

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