Youtube API V3 和 Etag [英] Youtube API V3 and Etag

查看:47
本文介绍了Youtube API V3 和 Etag的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 youtube api v3,我想了解 Etag.我想将它用于缓存目的,但我不知道在 PHP 中该做什么.你能告诉我 etag 恢复后要遵循的步骤吗?请.感谢您的帮助.

I use the youtube api v3 and i would like to understand how does the Etag. I would like to use it for what it takes to cache purpose but I do not know what to do in PHP. Could you tell me the steps to follow once the etag recovered ? please. Thanks for help.

推荐答案

根据 youtube 文档 (https://developers.google.com/youtube/v3/getting-started#etags),eTag 基本上用于确定资源是否已更改.将它们用于:

According to the youtube docs (https://developers.google.com/youtube/v3/getting-started#etags), an eTag is basically used to determine if a resource has changed. Use them for:

  1. 优化 - 在您的应用中缓存 YouTube 资源可以减少带宽和延迟.缓存时,存储 eTag,以便在获取资源时可以包含它.如果资源没有改变,你会得到一个 304 响应代码(NOT MODIFIED),这意味着你可以使用你的缓存版本.否则,您将获得资源的更新版本.

  1. Optimization - Caching youtube resources in your app can reduce bandwidth and latency. When caching, store the eTag so that you can include it when getting a resource. If the resource has not changed, you will get a 304 response code (NOT MODIFIED), which means you can use your cached version. Otherwise, you will get the updated version of the resource.

配额使用 - 您可以通过缓存 youtube 数据来减少使用配额的数量.第一次获得资源时,您将使用配额.在显示资源之前,首先检查您的缓存资源是否发生了变化,这只会花费您 1 个配额单位.如果资源没有改变,youtube 会返回 304 响应.如果它发生了变化,您可以再次获得资源,根据您获得的资源消耗不同的配额单位.有关配额的更多信息:(https://developers.google.com/youtube/v3/getting-started#quota).

Quota Usage - You can reduce the amount you tap into your quota by caching youtube data. The first time you get the resource, you will tap into your quota. Before displaying the resource, first check to see if your cached resource has changed, which will only cost you 1 quota unit. If the resource has not changed, youtube will return a 304 response. If it has changed, you can get the resource again, costing various quota units depending on what you are getting. For more on your quota: (https://developers.google.com/youtube/v3/getting-started#quota).

覆盖保护 - 如果您要覆盖资源,包含 eTag 将确保您不会覆盖资源的较新版本.

Overwrite protection - If you are overwriting a resource, including the eTag will ensure that you are not overwriting a newer version of the resource.

eTag 是 HTTP 1.1 规范的一部分(http:///www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.19) 并在请求/响应的标头中使用.这里有一篇很好的文章,在低层次上讨论了它们:http://www.ibuildings.com/blog/2013/07/etags-uninitiated

eTags are part of the HTTP 1.1 spec (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.19) and are used in the headers of the request/response. Here's a good article that talks about them at a low level: http://www.ibuildings.com/blog/2013/07/etags-uninitiated

至于在 PHP 中使用 eTags,我只能建议几件事,因为我从未这样做过.YouTube 为供稿和供稿中的单个项目返回电子标签,我不确定如何将它们用于供稿中的单个项目.但是要获取原始提要本身,基本上您将使用 curl 并将 eTag 添加到您的请求的标头中 (PHP cURL 自定义标头).您可能还想查看 http_cache_etag (http://www.php.net/manual/en/function.http-cache-etag.php)

As far as using eTags in PHP, I can only suggest a couple things since I've never done it. YouTube returns eTags for feeds AND individual items within a feed, and I'm not sure how to use them for individual items within a feed. But to get the original feed itself, essentially you would use curl and add the eTag to the header of your request (PHP cURL custom headers). You might also want to check out http_cache_etag (http://www.php.net/manual/en/function.http-cache-etag.php)

这篇关于Youtube API V3 和 Etag的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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