dttnb997315 2015-01-15 23:14
浏览 68
已采纳

从Imgur API检索图像

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.

  • 写回答

1条回答 默认 最新

  • dongyin0628 2015-01-16 00:26
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果