【问题标题】:API get value TumblrAPI 获取价值 Tumblr
【发布时间】:2012-05-02 11:24:34
【问题描述】:

我正在尝试使用 Tumblrs API,当我访问 API 的 URL 时,我在下面看到了这个

{
    "meta": {
        "status": 200
        "msg": "OK",
    },
    "response": {
        "blog": {
            "title": "Ex-Sample",
            "posts": 20,
            "name": "example",
            "url": "http://example.tumblr.com/",
            "updated": 1327794725,
            "description": "A sample document used to provide examples of the various [and <i>varying</i>] HTML tags Tumblr puts out. Quote, specifically, has a lot of variants.",
            "ask": false
        }
    }
}

网址是http://api.tumblr.com/v2/blog/example.tumblr.com/info?api_key=(APIKEY)

我正在尝试通过上面的 URL 获取“帖子”编号。我将如何在 PHP 中执行此操作并仅将数字回显出来?。

【问题讨论】:

    标签: php api tumblr


    【解决方案1】:

    这看起来像一个 JSON 字符串,所以...

    $msg = '{"meta" etc.....';
    $data = json_decode($msg);
    echo $data['meta']['response']['blog']['posts'];
    

    你可以使用

    var_dump($data);
    

    以格式良好的树结构转储整个响应。

    【讨论】:

    • 很简单,我的问题是如何将 url 放入 $msg var 这里是 url api.tumblr.com/v2/blog/example.tumblr.com/…
    • 您将如何实际获取该数据? file_get_contents($url) 是最简单的,但如果不可用,还有 cURL 和其他一些选项。
    • 你会如何使用 file_get_contents($url) 你能给我一个例子吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多