从Guardian API获取文章文本

时间:2015-12-05 16:44:34

标签: javascript api object

从“卫报”的新闻API获取文章文字时遇到问题。我有一个这样的网址:http://content.guardianapis.com/search?section=technology&api-key=MYKEY 我得到的答案如下:

{
"response": {
    "status": "ok",
    "userTier": "developer",
    "total": 54530,
    "startIndex": 1,
    "pageSize": 10,
    "currentPage": 1,
    "pages": 5453,
    "orderBy": "newest",
    "results": [{
        "type": "article",
        "sectionId": "technology",
        "webTitle": "Net neutrality has its day in court – with lawyers, Christians and the Cheshire Cat",
        "webPublicationDate": "2015-12-05T12:30:06Z",
        "id": "technology/2015/dec/05/net-neutrality-has-its-day-in-court-with-lawyers-christians-and-the-cheshire-cat",
        "webUrl": "http://www.theguardian.com/technology/2015/dec/05/net-neutrality-has-its-day-in-court-with-lawyers-christians-and-the-cheshire-cat",
        "apiUrl": "http://content.guardianapis.com/technology/2015/dec/05/net-neutrality-has-its-day-in-court-with-lawyers-christians-and-the-cheshire-cat",
        "sectionName": "Technology"
    }, {
        "type": "article",
        "sectionId": "technology",
        "webTitle": "Five things we love: from a school-proof tablet to a ghostly Serbian bicycle",
        "webPublicationDate": "2015-12-05T10:00:02Z",
        "id": "technology/2015/dec/05/five-things-we-love",
        "webUrl": "http://www.theguardian.com/technology/2015/dec/05/five-things-we-love",
        "apiUrl": "http://content.guardianapis.com/technology/2015/dec/05/five-things-we-love",
        "sectionName": "Technology"
    }, {
        "type": "article",
        "sectionId": "technology",
        "webTitle": "Don’t listen to those who try to own the definition of a video game",
        "webPublicationDate": "2015-12-04T12:00:21Z",
        "id": "technology/2015/dec/04/video-games-gaming-dudegamers",
        "webUrl": "http://www.theguardian.com/technology/2015/dec/04/video-games-gaming-dudegamers",
        "apiUrl": "http://content.guardianapis.com/technology/2015/dec/04/video-games-gaming-dudegamers",
        "sectionName": "Technology"
    }]
}
}

并且不包含文章文本,只包含新闻页面的网址。 我的问题是如何获取文章文字?

2 个答案:

答案 0 :(得分:6)

尝试添加show-blocks=all&进行查询,例如。在url返回属性"bodyTextSummary"。以下网址可细分为:
基本网址: http://content.guardianapis.com/search?
搜索参数开始: q=
搜索参数(所有“”替换为“%20”): 12%20years%20a%20slave&
转换为json格式: format=json&
按特定代码进行过滤: tag=film/film,tone/reviews&
按开始日期过滤: from-date=2010-01-01&
按相关性排序: order-by=relevance&
显示完整的API哈希: show-blocks=all&
您的API密钥(应将您的密钥放在“测试”位置): api-key=test

http://content.guardianapis.com/search?q=12%20years%20a%20slave&format=json&tag=film/film,tone/reviews&from-date=2010-01-01&order-by=relevance&show-blocks=all&api-key=test

请参阅http://open-platform.theguardian.com/documentation/search

答案 1 :(得分:0)

使用show-fields密钥和bodyText键值到您的网址,然后您就会获得内容。

例如:show-fields = BodyText

http://content.guardianapis.com/search?order-by=newest&show-fields=bodyText&q=politics&api-key=test