格式化 api url 以仅返回 videoId.(并使用最小配额) [英] Formating the api url to return only the videoId. (And use minimal quota)

查看:21
本文介绍了格式化 api url 以仅返回 videoId.(并使用最小配额)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我使用 Home Assistant 来启动一个自动化来检索一个频道上传的最新 videoId,所以我可以使用我的 google home 来播放它(在 Roku 电视上),工作正常,我正在创建一个也执行 GET 请求的自动化,但现在,我正在使用家庭助理休息传感器,该传感器通过在设定的秒数后执行 GET 进行更新,但出于某种原因,尽管每分钟只轮询 3 个传感器,但似乎他们使用大约 100-500 配额(仅在几个小时或更短的时间内达到我的 10,000 配额),我不确定这是家庭助理问题还是我没有正确使用 api(我只需要 videoId),我的网址链接如下:

So I'm using Home Assistant to launch an automation that retrieves the newest videoId that a channel has uploaded, so I can use my google home to play it(on a Roku TV), works fine, I am working on creating an automation that also does a GET request but for now, I am using the home assistant rest sensor that updates by performing a GET after a set number of seconds, for some reason though there are only 3 sensors polled every minute or so it seems they use around 100-500 quota(hitting my quota of 10,000 after only a few hours or less), I'm not sure if this is a home assistant problem or if I am not using the api correctly(I only need the videoId), ill link my url below:

https:///www.googleapis.com/youtube/v3/search?key=API_KEY&part=id&order=date&maxResults=1

预计每个 GET 使用 1-3 个配额,每个 GET 使用超过 100 个配额.

Expected 1-3 quota usage per GET, getting 100+ quota usage per GET.

推荐答案

查询搜索端点 is 比查询给定用户的上传播放列表的 PlaylistItems 端点更昂贵.根据使用模式,默认配额可能会对允许用户在 API 的各个端点上进行的调用次数.

Querying the Search Endpoint is more expensive than querying the PlaylistItems endpoint for the given user's uploads playlist. Depending on usage patterns, the default quotas may put rather tight limits on the number of calls an user is allowed to make on various endpoints of the API.

我的回答调整到另一个问题,我建议您改为执行以下操作:致电 PlaylistItems 端点,作为给定频道的 playlistId 参数传递给它上传播放列表 ID.

Adapting my answer to a different question, I suggest you to do the following instead: call PlaylistItems endpoint, passing to it as playlistId parameter the given channel's uploads playlist ID.

在查询 频道自己的端点.所需的 ID 可在 .items 中找到.contentDetails.relatedPlaylists.uploads.通常,频道 ID 与其对应的上传播放列表 ID 通过 s/^UC([0-9a-zA-Z_-]{22})$/UU\1/ 相关联.

A given channel's uploads playlist ID is obtained upon querying the channel's own endpoint. The needed ID is to be found at .items.contentDetails.relatedPlaylists.uploads. Usually, an channel ID and its corresponding uploads playlist ID are related by s/^UC([0-9a-zA-Z_-]{22})$/UU\1/.

请注意,您应该只查询 Channels 端点一次,然后根据需要多次使用返回的上传播放列表 ID.

Note that you should query the Channels endpoint only once, then use the returned uploads playlist ID as many times as you need.

另请注意,您可以使用应用的 fields 参数进行试验对于您的查询,仅从 API 部分资源获取.但是,我预测(我很可能错了,因为没有对其进行测试)查询 PlaylistItems 的 contentDetails 对象的成本无法提高.

Also note that you may experiment using the fields parameter applied to your queries, as to get from the API partial resources only. However, I'm predicting that (I may well be wrong, since did not tested it) the cost of 3 points for querying PlaylistItems for its contentDetails object cannot be improved.

这是一个原型网址:

https://www.googleapis.com/youtube/v3/playlistItems?key=APP_KEY&part=contentDetails&fields=items/contentDetails/videoId&maxResults=1&playlistId=PLAYLIST_ID

这篇关于格式化 api url 以仅返回 videoId.(并使用最小配额)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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