如果使用httr GET时不考虑是否使用If-Modified-Since? [英] If-Modified-Since not considered while using httr GET?

查看:130
本文介绍了如果使用httr GET时不考虑是否使用If-Modified-Since?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的要求/目标:

我将从公共页面上检索过去3个月中的Facebook帖子,我只选择最近(过去2天)中已被修改的帖子.

I'm retrieving Facebook posts for the past 3 months from a public page, and I would like to select only those posts which have been modified in the recent past (in the last 2 days).

我正在使用httr R程序包,并使用GET函数来完成上述操作.

I'm using httr R package, and using the GET function to accomplish the above.

我尝试了以下方法:

  1. url.data<-GET(URL,config(token = token),config(add_headers("If-Modified-Since" ="2016-09-08 11:45")))

  1. url.data <- GET(url, config(token=token), config(add_headers("If-Modified-Since" = "2016-09-08 11:45")))

url.data<-GET(URL,config(token = token,add_headers("If-Modified-Since" ="2016-09-08 11:45"))

url.data <- GET(url, config(token=token, add_headers("If-Modified-Since" = "2016-09-08 11:45"))

在上面的"url"中有"since","until"字段指定时间 需要检索帖子的期限(3个月). 令牌"是用于身份验证的OAuth令牌.

In the above 'url' has the 'since', 'until' fields specifying the time period (3 months) for which the posts need be retrieved. 'token' is the OAuth token for authentication.

在上述两种方法中,所有帖子都将被检索,而不仅仅是过去两天修改过的帖子.

In both of the above methods, all the posts are retrieved, rather than just the posts that are modified in the past 2 days.

是否还有另一种将If-Modified-Since传递给GET的方法,该方法只会导致只检索所需的帖子?

Is there another way of passing the If-Modified-Since to GET which will result in only the desired posts to be retrieved?

注意:我已经检查了这些与If-Modified-Since相关的帖子,它们没有回答我的问题:

Note: I have already checked these posts related to If-Modified-Since, and they do not answer my question :

  1. "If-Modified-Since"标头
  2. "If-Modified-Since"标头?
  3. 如果自-HTTP协议以来进行了修改
  4. If-Modified-Since Date Format
  1. "If-Modified-Since" header
  2. "If-Modified-Since" Header?
  3. If modified since - HTTP protocol
  4. If-Modified-Since Date Format

还有一些与我的情况不完全相关的问题.

and a few more questions which are not exactly related to my scenario.

任何帮助将不胜感激.

推荐答案

我认为您问题的核心是"If-Modified-Since"标头的目的与Facebook过滤结果之间的混淆.

I think the core of your issue here is a confusion between the purpose of the "If-Modified-Since" header, and the filtering of results by Facebook.

"If-Modified-Since"询问服务器自此日期/时间以来,我调用此URL/更改此查询时是否返回了内容?"

"If-Modified-Since" asks the server "Did the contents to be returned when I call this URL/make this query change since this date/time?"

发送到Facebook的自"和直到"参数对请求进行过滤,以仅显示在这两个日期之间发布的内容.

The "since" and "until" parameters sent to Facebook filter the request to only show content which was posted between those two dates.

Facebook不会将两者合并以返回满足两个问题的帖子-属于参数中设置的两个日期/时间之间,并且自使用"If-Modified-Since"设置的日期/时间以来已被修改.

Facebook will not merge the two to return posts which satisfy both questions - which fall between the two date/times set in the parameters and have been modified since the date/time set with "If-Modified-Since".

这是因为Facebook执行搜索/过滤器,查看整个响应并回答以下问题:自该日期/时间以来,当我调用此URL/使此查询发生更改时,返回的内容是否已更改?"根据整体回应.如果整个回复中有任何更改,则会将整个回复发送给您.

This is because Facebook performs the search/filter, looks at the entirety of the response and answers that question "Did the contents to be returned when I call this URL/make this query change since this date/time?" based on the whole response. If anything has changed in the entire response, then it will send the entire response to you.

如果要标识已更改的各个帖子,则必须遍历数组并单独检查每个元素.

If you want to identify individual posts which have changed, you will have to loop through the array and check each element individually.

这篇关于如果使用httr GET时不考虑是否使用If-Modified-Since?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆