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

Downloading a remote media file failed. #187

Closed abunour22 closed 7 years ago

abunour22 commented 7 years ago

Hello,

I've received an error when trying to upload an image from an URL:

    \Codebird\Codebird::setConsumerKey(twitterConsumerKey, twitterConsumerSecret);
    $cb = \Codebird\Codebird::getInstance();
    $cb->setToken($AccessToken, $AccessTokenSecret);

    $reply = $cb->media_upload([
        'media' => $image
    ]);

    $mediaID = $reply->media_id_string;

    $params = [
        'status'    => $message,
        'media_ids' => $mediaID
    ];

    $reply = $cb->statuses_update($params);

But it returns " Downloading a remote media file failed. "

Note: The same URL is used for the Instagram thumbnail and it was published, so I don't think it comes from the image or webserver.

mynetx commented 7 years ago
  1. Which URL are you using? 2. Does your webserver firewall allow outgoing connections? 3. Is the URL a redirection?
mynetx commented 7 years ago

Closing due to no further reply.

RayFlow commented 7 years ago

I was having the same problem, apache error log:

PHP Fatal error: Uncaught Codebird\CodebirdMediaException: Downloading a remote media file failed (... ) /var/www/html/twitter2/codebird/src/codebird.php on line 1891

I was using the absolute path (eg: https://example.com/imagefolder/imagefile.png) at first.

Solution: use the relative path of the image file (eg: ../imagefolder/imagefile.png) // check if and how many folders you need to get out: ../../ or same: ./

mynetx commented 7 years ago

@RayFlow Can you explain this with a complete sample, please? This would help us (and others!) understand your solution better. :)