KH_AJU
KH_AJU

Reputation: 119

REST api 'The gurdian' get image URL

Am working on a news app which fetch data from 'The guardian' using the RESTapi http://open-platform.theguardian.com/explore/

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

I will get a response similar to this

{
"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
    }]
}
}

I need to include one main picture for each headline; but the response data doesn't contains any image URL. Is it possible to get image URL using any methods; please help me on this...

Upvotes: 2

Views: 1331

Answers (2)

Elvin Shahsuvarli
Elvin Shahsuvarli

Reputation: 636

Or you can add &show-elemets=image to your API endpoint and get elements property in response. See below example

http://content.guardianapis.com/search?page=20&q={query}&api-key={myKey}&show-elements=image

see documentation

Upvotes: 0

Dan Cantir
Dan Cantir

Reputation: 2955

You must include &show-fields=thumbnail in your request URL like this: http://content.guardianapis.com/search?page=20&q={query}&api-key={myKey}&show-fields=thumbnail

Upvotes: 11

Related Questions