我正在尝试为 CMS 网站制作一个小部件,我可以在管理页面上对我的用户进行身份验证,然后显示下一个 YouTube 直播的计时器并从我的页面直接链接到它。
我已成功使用 youtube.liveBroadcasts.list
API 并收到了我的广播列表并将其显示在页面上。但我希望能够在其他用户访问页面时在页面上显示此信息(关于我的 channel ),而无需登录或使用任何类型的身份验证。
最佳答案
我认为要使用来自 Youtube API 的此请求,需要登录。例如,当您将其粘贴到浏览器中时 LiveBroadcasts.list浏览器中的 URI 请求
https://www.googleapis.com/youtube/v3/liveBroadcasts
如果没有登录,您会收到错误消息:
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Login Required",
"locationType": "header",
"location": "Authorization",
我认为阅读Implementing OAuth 2.0 Authorization也会有帮助。 .
以下是支持的 OAuth 流程:
- The server-side flow supports web applications that can securely store persistent information.
- The client-side flow supports JavaScript applications running in a browser.
- The installed application flow supports applications installed on a device, such as a phone or computer.
- The device flow supports devices with limited input capabilities, such as game consoles and video cameras.
*The service account flow supports server-to-server interactions that do not access user information. However, the YouTube Data API does not support this flow. Since there is no way to link a Service Account to a YouTube account, attempts to authorize requests with this flow will generate a NoLinkedYouTubeAccount error.
简而言之,我认为您需要获得授权才能执行此 API 调用。
关于javascript - 无需身份验证即可使用 Youtube API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40193529/