在特定日期范围内搜索博客api v3

问题描述:

如果我们想要使用博客API API v3搜索google博客帖子,那么我们应该按照here中的文档。但是我们如何在查询参数q中整合一个日期范围呢?我试过q=startDate:2016-01-01:T00:00:00+endDate:2017-09-05:T00:00:00但它不起作用。在特定日期范围内搜索博客api v3

我也试过从某个日期开始搜索帖子,使用q=startDate:2016-01-01:T00:00:00q=startDate:"2016-01-01:T00:00:00"q=startDate:2016-01-01但仍然不起作用。 URL编码是正确完成的,因为我使用标签搜索进行测试,如q=label:symbols|label:fonts,用于搜索包含标签symbols或标签fonts的帖子,它工作得很好。

经过一番搜索,我终于发现答案在那里,但我没有仔细看。当我们要搜索特定日期范围内的帖子时,我们不会查询search:posts操作,而是查询list:posts操作。例如,如果我们想要搜索October 2, 2016September 7, 2017我们发送以下形式的请求URL:

https://www.googleapis.com/blogger/v3/blogs/{blogID}/posts? startDate=2016-10-02T00:00:00z&endDate=2017-09-07T00:00:00z &callback=handleResponse&key={our_received_key}

handleResponse是当成功地接收响应这就是所谓的回调函数。上述网址查询无效,因为我们也收到帖子的正文文字,这会影响效果。还必须使用分页。第一个通过设置fetchBodies=false实现,第二个通过使用maxResultspageToken实现。

它封装上述评论简化脚本可以是:

<!DOCTYPE html> 
 
<html> 
 
<head> 
 
    <title>Blogger API Example</title> 
 
</head> 
 
<body> 
 
    <div id="content"></div> 
 
    <script> 
 
     function handleResponse(response) { 
 
      var post = ""; 
 
      for (var i in response.items) 
 
      { 
 
       document.getElementById("content").innerHTML += "<a href=\"" + response.items[i].url + 
 
        "\">" + response.items[i].title + "</a>" + "<br/>"; 
 
      } 
 
     } 
 
    </script> 
 
    <script src='https://www.googleapis.com/blogger/v3/blogs/35636577512/posts?startDate=2016-10-02T00:00:00z&endDate=2017-09-07T00:00:00z&maxResults=10&fetchBodies=false&callback=handleResponse&key=RTza3456gfhf_Q345fgh'></script> 
 
</body> 
 
</html>

如果柱的总数大于它是10的例子中的的maxResults,则nextPageToken将更大被发送,可以通过response.nextPageToken检索并存储在下一个url查询中。

https://www.googleapis.com/blogger/v3/blogs/35636577512/posts?startDate=2008-10-02T00:00:00z&endDate=2016-09-06T17:30:00z&pageToken=dfgdfRtdfdf234rT&fetchBodies=false&callback=handleResponse&key=RTza3456gfhf_Q345fgh'