youtube api v3/search 是否支持 etags? [英] Does the youtube api v3/search support etags?

查看:31
本文介绍了youtube api v3/search 是否支持 etags?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 etags 以减少我的带宽和我的配额使用量,但/search 即使没有任何变化也会返回一个新的 etag.如果我在标题中指定了前一个 etag,它也会发送内容.

I'm trying to use etags in order to reduce both my bandwidth and my quota usage but /search returns an new etag even when nothing changed. It also still sends the content if I specify the previous etag in the header.

它是否支持该 api 调用,还是我可能做错了什么?

Is it supported for that api call or am I probably doing something wrong?

推荐答案

Etags 由 youtube 支持,但这取决于您要询问的数据类型

Etags are supported by youtube but it depends on what kind of data you are asking

ETags 是 HTTP 协议的标准部分,允许应用程序引用特定 API 资源的特定版本.资源可以是整个提要或该提要中的项目.此功能支持以下用例:

ETags, a standard part of the HTTP protocol, allow applications to refer to a specific version of a particular API resource. The resource could be an entire feed or an item in that feed. This functionality supports the following use cases:

缓存和条件检索——您的应用程序可以缓存 API资源及其 ETag.然后,当您的应用程序请求再次存储资源,它指定与该资源关联的 ETag资源.如果资源发生了变化,API 返回修改后的资源和与该资源版本关联的 ETag.如果资源未更改,API 返回 HTTP 304 响应(Not Modified),表示资源没有改变.您的应用程序可以通过提供服务来减少延迟和带宽使用以这种方式缓存资源.

Caching and conditional retrieval – Your application can cache API resources and their ETags. Then, when your application requests a stored resource again, it specifies the ETag associated with that resource. If the resource has changed, the API returns the modified resource and the ETag associated with that version of the resource. If the resource has not changed, the API returns an HTTP 304 response (Not Modified), which indicates that the resource has not changed. Your application can reduce latency and bandwidth usage by serving cached resources in this manner.

Google API 的客户端库在对 ETag 的支持方面有所不同.例如,JavaScript 客户端库通过允许的请求标头的白名单,包括 If-Match 和如果-无-匹配.白名单允许正常的浏览器缓存发生如果资源的 ETag 没有改变,则可以为该资源提供服务从浏览器缓存.另一方面,Obj-C 客户端不会支持 ETag.防止无意中覆盖更改 –ETag 有助于确保多个 API 客户端不会无意中覆盖彼此的变化.更新或删除资源时,您的应用程序可以指定资源的 ETag.如果 ETag 没有匹配该资源的最新版本,然后匹配 API 请求失败.

The client libraries for Google APIs differ in their support of ETags. For example, the JavaScript client library supports ETags via a whitelist for allowed request headers that includes If-Match and If-None-Match. The whitelist allows normal browser caching to occur so that if a resource's ETag has not changed, the resource can be served from the browser cache. The Obj-C client, on the other hand, does not support ETags. Protecting against inadvertent overwrites of changes – ETags help to ensure that multiple API clients don't inadvertently overwrite each other's changes. When updating or deleting a resource, your application can specify the resource's ETag. If the ETag doesn't match the most recent version of that resource, then the API request fails.

在您的应用程序中使用 ETag 有几个好处:

Using ETags in your application provides several benefits:

API 对缓存但未更改的请求的响应速度更快资源,产生更低的延迟和更低的带宽使用.您的应用程序不会无意中覆盖对资源的更改来自另一个 API 客户端.

The API responds more quickly to requests for cached but unchanged resources, yielding lower latency and lower bandwidth usage. Your application will not inadvertently overwrite changes to a resource that were made from another API client.

https://developers.google.com/youtube/v3/getting-开始#etags

我通常会抓取 Youtube 进行视频搜索,我只存储它返回的 Etag.要使用 etag,请创建一个标头请求并将If-None-Match"设置为等于您的 etag 值.请注意,这应该是请求标头,而不是附加到端点调用.您也可以使用If-Match".

I usually scrape Youtube for Videos searches and I just store the Etag that it return. To use the etag, create a header request and put "If-None-Match" equal to your etag value. Note this should be a request header and not appended to the endpoint call. You can also use "If-Match".

根据您使用的 API 类型,向请求标头插入新值的方式可能略有不同

Depending on what kind of API you are using, the way of inserting a new value to the request header may differ slightly

这篇关于youtube api v3/search 是否支持 etags?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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