优化对 YouTube API 的查询 [英] Optimize query to YouTube API

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

问题描述

帮助优化 YouTube API 请求.整个配额在 5 分钟内用完

Help optimize YouTube API requests. The entire quota is spent in 5 minutes

获取 id TOP 5 趋势:

Get id TOP 5 trends:

https://www.googleapis.com/youtube/v3/videos?part=contentDetails&key={token}&fields=items(id)&chart=mostPopular&regionCode=RU&maxResults=5 

从视频 ID 中获取频道 ID 和频道名称:

Get channel id and channel name from video id:

https://www.googleapis.com/youtube/v3/videos?part=snippet&id={VideoId}&key={token}

从用户名获取频道名称

https://www.googleapis.com/youtube/v3/channels?key={token}&forUsername={UserName}&part=id

获取频道图片:

https://www.googleapis.com/youtube/v3/channels?id={ChannelId}&part=snippet&key={token}

频道上的视频数:

​https://www.googleapis.com/youtube/v3/playlistItems?playlistId={ChannelId}&key={token}&part=snippet

频道上的最后一个视频:

Last video on channel:

https://www.googleapis.com/youtube/v3/search?key={token}&channelId={ChannelId}&part=id&order=date&maxResults=1

推荐答案

以下是一些我认为可能会有所帮助的提示:

These are a few tips I think it might help:

  1. 设置要在每个请求中检索的特定字段.
  2. 搜索"请求比其他请求消耗更多配额.

这是您修改后的请求:

获取 id TOP 5 趋势 - 演示:

Get id TOP 5 trends - Demo:

https://www.googleapis.com/youtube/v3/videos?part=contentDetails&chart=mostPopular&hl=<REGION_CODE>&maxResults=5&fields=items%2Fid&key={YOUR_API_KEY}

从视频 ID 中获取频道 ID 和频道名称: - 演示

Get channel id and channel name from video id: - demo

https://www.googleapis.com/youtube/v3/videos?part=snippet&id=<VIDEO_ID>&fields=items(snippet(channelId%2CchannelTitle))&key={YOUR_API_KEY}

从用户名中获取频道名称​​(同时提供频道图片及其上传视频的数量) - 演示

Get channel name from username (also bring at the same time the channel image and its count of uploaded videos) - demo

https://www.googleapis.com/youtube/v3/channels?part=snippet%2Cstatistics&forUsername=<CHANNEL_USERNAME>&fields=items(snippet(thumbnails%2Ctitle)%2Cstatistics%2FvideoCount)&key={YOUR_API_KEY}

频道上的最后一个视频:- 演示

Last video on channel: - demo

这里你可以使用其他方法:

Here you can use other approach:

  • 使用 channel_id 并按如下所示替换值:
  • Use the channel_id and replace the value as follows:

频道:Microsoft Hololens:

Channel: Microsoft Hololens:

Channel_id:UCT2rZIAL-zNqeK1OmLLUa6g

Channel_id: UCT2rZIAL-zNqeK1OmLLUa6g

上传(播放列表):UUT2rZIAL-zNqeK1OmLLUa6g

Uploads (playlist): UUT2rZIAL-zNqeK1OmLLUa6g

获得上传(播放列表)后,使用以下请求:

Once you get the uploads (playlist), use the following request:

https://www.googleapis.com/youtube/v3/playlistItems?part=contentDetails&playlistId=<UPLOAD_PLAYLIST>&fields=items(contentDetails(videoId%2CvideoPublishedAt))&key={YOUR_API_KEY}

并使用响应中最新的 videoId - (具有最近更新时间).

And use the latest videoId from the response - (which has the most recent updated time).

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

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