我在使用 oAuth 的电子表格中开发了一个谷歌应用程序脚本。我现在将相同的脚本复制到在站点上运行的小工具中。当我想运行使用 oauth 的函数时,出现以下错误:
序列化延续时出现意外异常
当我在站点上运行实际小工具或从脚本编辑器运行函数时,都会发生这种情况。从电子表格中的脚本编辑器调用完全相同的代码。是我做错了什么,还是在使用站点小工具时根本无法将 oAuth 与 UrlFetchApp.fetch 一起使用?
谢谢,
简
这是我正在尝试做的一些示例代码,您需要包含来自 Google Api 控制台的真实 api 机密来测试它。
function CalendarApiBug( ) {
var oAuthConfig = UrlFetchApp.addOAuthService('agenda scheduler');
oAuthConfig.setRequestTokenUrl("https://www.google.com/accounts/"+
"OAuthGetRequestToken?scope=https://www.googleapis.com/auth/calendar");
oAuthConfig.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken");
oAuthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");
oAuthConfig.setConsumerKey('replacemewithsomethingreal');
oAuthConfig.setConsumerSecret('replacemewithsomethingreal');
this.baseUrl = 'https://www.googleapis.com/calendar/v3/';
this.calendarsList = null;
this.getBaseUrl = function() {
return this.baseUrl;
} //CalendarApiBug.getBaseUrl
this.getFetchArgs = function() {
return {oAuthServiceName:'agenda scheduler', oAuthUseToken:"always"};
} //CalendarApiBug.getFetchArgs
this.getCalendarList = function(refresh){
if (refresh != true && this.calendarsList != null )
return this.calendarsList;
var fetchArgs = this.getFetchArgs();
fetchArgs.method = 'get';
var url = this.baseUrl + 'users/me/calendarList';
this.calendarsList = Utilities.jsonParse(UrlFetchApp.fetch(url, fetchArgs).getContentText());
return this.calendarsList;
} //CalendarApiBug.getCalendarList
}
function test(){
var api = new CalendarApiBug();
Logger.log(api.getCalendarList(false));
}