REST api' gurdian'获取图片网址

时间:2016-11-21 13:05:19

标签: android rest

正在处理一个新闻应用程序,该应用程序从监护人那里获取数据'使用RESTapi http://open-platform.theguardian.com/explore/

 http://content.guardianapis.com/search?page=20&q=business%20OR%20sport&api-key={myKey}

我会得到与此相似的回复

{
"response": {
    "status": "ok",
    "userTier": "developer",
    "total": 80009,
    "startIndex": 191,
    "pageSize": 10,
    "currentPage": 20,
    "pages": 8001,
    "orderBy": "relevance",
    "results": [{
        "id": "sport/2016/aug/03/lizzie-armitstead-responds-statement-twitter-missed-tests-olympics-rio",
        "type": "article",
        "sectionId": "sport",
        "sectionName": "Sport",
        "webPublicationDate": "2016-08-03T11:14:46Z",
        "webTitle": "Lizzie Armitstead hits back: I love my sport but I would never cheat for it",
        "webUrl": "https://www.theguardian.com/sport/2016/aug/03/lizzie-armitstead-responds-statement-twitter-missed-tests-olympics-rio",
        "apiUrl": "https://content.guardianapis.com/sport/2016/aug/03/lizzie-armitstead-responds-statement-twitter-missed-tests-olympics-rio",
        "isHosted": false
    }, {
        "id": "sport/2016/apr/03/mark-bonar-doctor-at-centre-of-doping-allegations-in-sport",
        "type": "article",
        "sectionId": "sport",
        "sectionName": "Sport",
        "webPublicationDate": "2016-04-03T14:10:50Z",
        "webTitle": "Mark Bonar: doctor at centre of doping allegations in sport",
        "webUrl": "https://www.theguardian.com/sport/2016/apr/03/mark-bonar-doctor-at-centre-of-doping-allegations-in-sport",
        "apiUrl": "https://content.guardianapis.com/sport/2016/apr/03/mark-bonar-doctor-at-centre-of-doping-allegations-in-sport",
        "isHosted": false
    }, {
        "id": "sport/blog/2016/apr/22/the-joy-of-six-sporting-tics",
        "type": "article",
        "sectionId": "sport",
        "sectionName": "Sport",
        "webPublicationDate": "2016-04-22T09:15:02Z",
        "webTitle": "The Joy of Six: sporting tics",
        "webUrl": "https://www.theguardian.com/sport/blog/2016/apr/22/the-joy-of-six-sporting-tics",
        "apiUrl": "https://content.guardianapis.com/sport/blog/2016/apr/22/the-joy-of-six-sporting-tics",
        "isHosted": false
    }, {
        "id": "business/2016/sep/20/sports-direct-bows-to-pressure-and-agrees-to-independent-review",
        "type": "article",
        "sectionId": "business",
        "sectionName": "Business",
        "webPublicationDate": "2016-09-20T09:58:23Z",
        "webTitle": "Sports Direct bows to pressure and agrees to independent review",
        "webUrl": "https://www.theguardian.com/business/2016/sep/20/sports-direct-bows-to-pressure-and-agrees-to-independent-review",
        "apiUrl": "https://content.guardianapis.com/business/2016/sep/20/sports-direct-bows-to-pressure-and-agrees-to-independent-review",
        "isHosted": false
    }]
}
}

我需要为每个标题添加一张主图片;但响应数据不包含任何图像URL。是否可以使用任何方法获取图像URL;请帮帮我...

1 个答案:

答案 0 :(得分:3)

您应在请求网址中加入&show-fields=thumbnail

像这样: http://content.guardianapis.com/search?page=20&q={query}&api-key={myKey}&show-fields=thumbnail

另外,请勿忘记查看the docs