来自纽约时报API(JSON)的查询在不同的搜索关键字上提供相同的输出?

时间:2015-04-24 18:26:46

标签: javascript json api

我正在尝试从新的时代API中获取JSON数据。以下是我正在使用的查询。它的编辑来自他们网站的示例查询。

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx =是我替换的api密钥,原因很明显。 " search_city_name" =到目前为止我应该把我的搜索关键字放在哪里。

问题:无论我想在查询中搜索什么,我都得到相同的结果。 查询:

http://api.nytimes.com/svc/search/v2/articlesearch.json?q="search_city_name"&sort=newest&&api-key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

例如,这是我得到的响应数组的第一个对象,无论我粘贴什么字符串而不是" search_city_name":

_id: "553a537238f0d87fad3b3cd7"
abstract: null
blog: Array[0]
byline: Object
document_type: "article"
headline: Object
keywords: Array[1]
lead_paragraph: "Cokie Roberts’s “Capital Dames,” No. 10 on the hardcover nonfiction list, is about powerful women in Washington during the Civil War era."
multimedia: Array[2]
news_desk: "BookReview"
print_page: "26"
pub_date: "2015-05-03T00:00:00Z"
section_name: "Books"
snippet: "Cokie Roberts’s “Capital Dames,” No. 10 on the hardcover nonfiction list, is about powerful women in Washington during the Civil War era."
source: "The New York Times"
subsection_name: "Sunday Book Review"
type_of_material: "News"
web_url: "http://www.nytimes.com/2015/05/03/books/review/inside-the-list.html"
word_count: "480"

更新: 查询的工作版本:

"http://api.nytimes.com/svc/search/v2/articlesearch.json?q="+ city +"&&api-key=xxxxxxxxxxxxxxxxxxxxxxxxxxx"

2 个答案:

答案 0 :(得分:1)

docs中给出的示例是http://api.nytimes.com/svc/search/v2/articlesearch.response-format?[q=search term&fq=filter-field:(filter-term)&additional-params=values]&api-key=####通常方括号表示可选参数。我敢打赌,如果你删除它,它会真正理解你发送和工作的内容。

答案 1 :(得分:0)

您是否正在使用Get方法从API获取数据,然后它会从之前的调用中提供缓存数据

所以请使用" post"而不是为特定请求获取或使缓存为false。