youtube api v3/search 支持 etags 吗?

Does the youtube api v3/search support etags?

我正在尝试使用 etag 来减少我的带宽和配额使用,但是 /search returns 一个新的 etag,即使没有任何改变。如果我在 header 中指定了先前的 etag,它仍然会发送内容。

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

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

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:

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.

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.

Using ETags in your application provides several benefits:

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-started#etags

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

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