2016-11-21 55 views
-1

我工作的新闻应用程序,它从“监护人”获取数据使用RESTAPI http://open-platform.theguardian.com/explore/REST API“的gurdian”获得图像URL

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 
    }] 
} 
} 
响应

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

回答

1

您应该在请求url中包含&show-fields=thumbnail

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

另外,不要忘记检查the docs