我正在尝试使用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频道从品牌切换为个人,然后我的个人电子邮件正常运行。但是,我需要在品牌帐户下使用它,因此我已切换回去。
无论如何,我都会保留这段代码,因为我发现缺少使用R的良好示例,希望您觉得这很有用。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句