I am using the Imgur API to pull down an array of random images using PHP. I cannot figure out for the life of me how to access the interior dimension of the returned array. This call:
$images = $client->api('gallery')->randomGalleryImages();
Returns this array slice
[0] => Imgur\Api\Model\GalleryImage Object
(
[accountUrl:Imgur\Api\Model\GalleryImage:private] =>
[ups:Imgur\Api\Model\GalleryImage:private] => 3115
[downs:Imgur\Api\Model\GalleryImage:private] => 67
[score:Imgur\Api\Model\GalleryImage:private] => 4109
[isAlbum:Imgur\Api\Model\GalleryImage:private] =>
[id:Imgur\Api\Model\Image:private] => HazyBBo
[title:Imgur\Api\Model\Image:private] => My big cat hugging his little kitty sister!
[description:Imgur\Api\Model\Image:private] =>
[datetime:Imgur\Api\Model\Image:private] => 1382472658
[type:Imgur\Api\Model\Image:private] =>
[animated:Imgur\Api\Model\Image:private] =>
[width:Imgur\Api\Model\Image:private] => 960
[height:Imgur\Api\Model\Image:private] => 720
[size:Imgur\Api\Model\Image:private] => 89895
[views:Imgur\Api\Model\Image:private] => 471653
[bandwidth:Imgur\Api\Model\Image:private] => 42399246435
[deletehash:Imgur\Api\Model\Image:private] =>
[section:Imgur\Api\Model\Image:private] => aww
[link:Imgur\Api\Model\Image:private] => http://i.imgur.com/HazyBBo.jpg
)
I've tried accessing it all the ways I know how, but I've never been presented with an array member such as this. The API documentation didn't immediately make it clear how to access an image returned with the API, and all of the questions/answers I've found pertaining to Imgur seem to reference uploading rather than displaying returned images.
It's a GalleryImage
object, and all of the fields are private. So you have to use the getters to access any information, like $images[0]->getLink()
. You can see the class code for Image (the parent class, which actually has the $link
field) and GalleryImage.