在tumblr搜索API中访问图像的URL

时间:2012-12-16 20:37:08

标签: php json multidimensional-array tumblr

我正在尝试使用标记搜索API来访问显示tumblr搜索的第一批图像的网址。下面是我正在使用的测试搜索的json。

    {
"meta": {
    "status": 200,
    "msg": "OK"
},
"response": [
    {
        "blog_name": "m00tzman",
        "id": 37918165271,
        "post_url": "http://m00tzman.tumblr.com/post/37918165271/test-image-for-tumblr-a…",
        "slug": "test-image-for-tumblr-api-thingy",
        "type": "photo",
        "date": "2012-12-14 18:13:25 GMT",
        "timestamp": 1355508805,
        "state": "published",
        "format": "html",
        "reblog_key": "IwlKk9r4",
        "tags": [
            "g6845e"
        ],
        "highlighted": [ ],
        "note_count": 29,
        "caption": "<p>test image for tumblr api thingy</p>",
        "photos": [
            {
                "caption": "",
                "alt_sizes": [
                    {
                        "width": 500,
                        "height": 628,
                        "url": "http://25.media.tumblr.com/af60fbe390c487125501e50b37781317/tumblr_…"
                    },
                    {
                        "width": 400,
                        "height": 502,
                        "url": "http://25.media.tumblr.com/af60fbe390c487125501e50b37781317/tumblr_…"
                    },
                    {
                        "width": 250,
                        "height": 314,
                        "url": "http://25.media.tumblr.com/af60fbe390c487125501e50b37781317/tumblr_…"
                    },
                    {
                        "width": 100,
                        "height": 126,
                        "url": "http://24.media.tumblr.com/af60fbe390c487125501e50b37781317/tumblr_…"
                    },
                    {
                        "width": 75,
                        "height": 75,
                        "url": "http://24.media.tumblr.com/af60fbe390c487125501e50b37781317/tumblr_…"
                    }
                ],
                "original_size": {
                    "width": 500,
                    "height": 628,
                    "url": "http://25.media.tumblr.com/af60fbe390c487125501e50b37781317/tumblr_…"
                }
            }
        ]
    }
]

}

我的问题是我无法回显“原始大小”图片的网址。到目前为止,这是我的代码:

    <?php
    $search = file_get_contents('http://api.tumblr.com/v2/tagged?tag=g6845e&api_key=(api key)');
    $tumblrdata = json_decode($search, true);
    $photos = $tumblrdata['photos']['original_size'];
    $url = $photos['url'];
    echo $url;
    ?>

对这里出了什么问题有任何猜测?

1 个答案:

答案 0 :(得分:0)

尝试

$photos = $tumblrdata['response']['photos'][0]['original_size'];