以下代码示例(使用适用于 Ruby 的 Google API 客户端库)适用于 YouTube Analytics API。您可以从 GitHub API 中的 YouTube API 代码示例代码库的 ruby
文件夹中下载这些代码示例。
授权请求
以下代码示例通过检查是否存在包含授权凭据的本地文件来执行 OAuth 2.0 授权。如果该文件不存在,脚本会打开一个浏览器并等待响应,然后将返回的凭据保存在本地。
require 'google/api_client' require 'google/api_client/client_secrets' require 'json' require 'launchy' require 'thin' RESPONSE_HTML = <OAuth 2 Flow Complete You have successfully completed the OAuth 2 flow. Please close this browser window and return to your program.