我正在尝试使用YouTube API使用Google AppScript从您的CMS帐户中提取数据。
我可以使用OAuth2成功获取令牌,我相信我有适当的范围,但当我尝试使用来自ISRC号码的视频ID填充我的Google电子表格时,我仍然收到401错误。
根据youtube合作伙伴开发人员OAuth2指南,我对OAuth2文件做了以下更改,以包含Youtube CMS的正确范围。
AUTHORIZE_URL = 'https://accounts.google.com/o/oauth2/auth'; //step 1. we can actually start directly here if that is necessary
var TOKEN_URL = 'https://accounts.google.com/o/oauth2/token'; //step 2. after we get the callback, go get token
var CLIENT_ID = 'MyClientId';
var CLIENT_SECRET = 'MyClientSecret';
var REDIRECT_URL= ScriptApp.getService().getUrl();
var tokenPropertyName = 'GOOGLE_OAUTH_TOKEN';
var baseURLPropertyName = 'GOOGLE_INSTANCE_URL';`enter code here`
function getURLForAuthorization(){
return AUTHORIZE_URL + '?response_type=code&client_id='+CLIENT_ID+'&redirect_uri='+REDIRECT_URL +
'&scope=https://www.googleapis.com/auth/youtubepartner'+'&access_type=offline'; //added access type from above api guide
}
但我仍然在这里收到错误:
https://www.googleapis.com/youtube/partner/v1/assetSearch?q=USY6C0700704&key=MyAPIKey_simple返回的代码401
请求失败请求看起来与我在API Explorer中所做的相同:
获取https://www.googleapis.com/youtube/partner/v1/assetSearch?q=USY6C0700704&key= {YOUR_API_KEY}
所以唯一认为可能出错的是我的令牌问题。
感谢你们,非常感谢任何帮助。
答案 0 :(得分:0)
您是否实际完成了OAuth流程并存储了访问/刷新令牌?
如果没有,请查看这两个YouTube视频,了解Apps脚本与数据和Analytics API的集成
http://www.youtube.com/watch?v=VVhsK5jH6u8 http://www.youtube.com/watch?v=eumC0nIw-lk
这些视频的代码可在此处获取 - https://github.com/entaq/GoogleAppsScript/tree/master/YouTube https://github.com/entaq/GoogleAppsScript/tree/master/IO2013/YouTubeAnalytics