我想为我的YouTube分析应用程序脚本应用程序获取授权令牌。。目前,我正在使用cGoa库获取this link中提供的一次需要身份验证的授权令牌。.但是出于安全考虑,我们不想使用所谓的cGoa库之类的外部脚本。请我需要知道其他方法来获取Google App脚本中的YouTube分析工具的Oauth2访问令牌。我们的主要目标ID是一劳永逸地拥有令牌,因为我们希望每天自动运行脚本。因此,我们需要可以一直工作而无需更多身份验证的东西。目前,这是我用于通过cGoa库获取令牌的代码。
function oneOffScript() {
var options = {
packageName: 'youtube-analytics', // user defined
clientId: '942097727718-t663ep631aqhd75610g4etpcn3foj827.apps.googleusercontent.com',
clientSecret:'Ng_9HJ34hKSPesvRA6hb85KR',
// following method to add Google scopes. Here we are mixing YouTube Data and Analytics (prefixed yt-)
// in the same service allowing calls to both APIs with the same token (we can do this because both are Google APIs)
// More on mixing services http://ramblings.mcpher.com/Home/excelquirks/goa/mutipleconsent
scopes : cGoa.GoaApp.scopesGoogleExpand (['youtube',
'youtube.force-ssl',
"youtubepartner",
"youtubepartner-channel-audit",
"yt-analytics-monetary.readonly",
"yt-analytics.readonly"]),
service:'google' // always this for Google APIs. Ref: http://ramblings.mcpher.com/Home/excelquirks/goa/services
};
// store one off in user properties
cGoa.GoaApp.setPackage(PropertiesService.getUserProperties(), options);
}
function doGet(e) {
var goa = cGoa.GoaApp.createGoa ('youtube-analytics',
PropertiesService.getUserProperties()).execute (e);
if (goa.needsConsent()) {
return goa.getConsent();
}
请高度赞赏您的回复。谢谢