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
776 stars 234 forks source link

media_upload issue #178

Closed manzoorwanijk closed 7 years ago

manzoorwanijk commented 8 years ago

Hi, I'm trying to update a status with media, but it doesn't work, the media ids are null

$files = ['image1.jpg', 'image2.jpg'];
$media_ids = [];

foreach ($files as $file) {
  $reply = $cb->media_upload([
    'media' => $file
  ]);
  $media_ids[] = $reply->media_id_string; // line 41
}
var_dump($media_ids);

the above code shows

Trying to get property of non-object in test.php on line 41

array(2) { [0]=> NULL [1]=> NULL }

and how do I upload a single file?

manzoorwanijk commented 8 years ago

I tried both on my localhost as well as my online server, but the result is same...

mynetx commented 8 years ago

Why closing?

manzoorwanijk commented 8 years ago

Sorry, that was my mistake...

mynetx commented 8 years ago

A single file would just be like this:

  $reply = $cb->media_upload([
    'media' => $file
  ]);
  $media_id = $reply->media_id_string;
mynetx commented 8 years ago

I just ran this code:

$file = 'bird1.jpg';

\Codebird\Codebird::setConsumerKey('***', '***');
$cb = \Codebird\Codebird::getInstance();
$cb->setToken("***", "***");

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

var_dump($reply);

And I got this reply:

object(stdClass)[2]
  public 'media_id' => int 771069797085880321
  public 'media_id_string' => string '771069797085880321' (length=18)
  public 'size' => int 191032
  public 'expires_after_secs' => int 86400
  public 'image' => 
    object(stdClass)[3]
      public 'image_type' => string 'image/jpeg' (length=10)
      public 'w' => int 1280
      public 'h' => int 1024
  public 'httpstatus' => int 200
  public 'rate' => 
    object(stdClass)[4]
      public 'limit' => string '415' (length=3)
      public 'remaining' => string '414' (length=3)
      public 'reset' => string '1472675940' (length=10)

Thus, your code should work definitely.

You have this line

  $media_ids[] = $reply->media_id_string; // line 41

What is shown if you peek into the server response, like this?

  var_dump($reply);
  $media_ids[] = $reply->media_id_string; // line 41
mynetx commented 7 years ago

Closing due to no further reply from OP.