我正在尝试使用 R 从 Youtube Analytics API 中提取数据并且遇到了障碍。我收到状态 403 错误。我可以确认:
更新
我找到了解决方案并将代码更新为现在可以使用的
scopes<- c('https://www.googleapis.com/auth/youtube.readonly')
endpoint<- oauth_endpoints('google')
youtubeapp<- oauth_app(appname='Youtube Analytics API',
key=client_id,
secret=client_secret)
youtube_token<- oauth2.0_token(
endpoint= oauth_endpoints('google'),
app = youtubeapp,
scope = scopes)
raw_data<- GET(paste("https://youtubeanalytics.googleapis.com/v2/reports?dimensions=",dimensions,"&endDate=",enddate,"&ids=",ids,"&metrics=",metrics,"&startDate=",startdate,sep=""),
config=youtube_token,content_type('application/json'))
content(raw_data, as= 'text')
最佳答案
我发现访问权限是由 Youtube(而不是 API IAM)决定的,因此例如,即使我的个人电子邮件是 Brand 帐户和 API 的所有者,我仍然需要使用 Brand 帐户对调用进行身份验证,否则它将无法工作(我收到个人电子邮件的 403 错误)。我尝试将我的 Youtube channel 从品牌 channel 切换到个人 channel ,然后我的个人电子邮件就起作用了。但是,我需要在品牌帐户下,所以我已经切换回来了。
不管怎样,我都会保留这段代码,因为我发现缺少使用 R 的好例子,我希望你觉得这很有用。
关于r - 使用 R 连接到 Youtube Analytics API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53270818/