oAuth를 사용하는 스프레드 시트에서 Google Apps 스크립트를 개발했습니다. 사이트에서 실행되는 가젯에 동일한 스크립트를 복사했습니다. 나는 OAuth를 나는 다음과 같은 오류 얻을 사용하는 기능을 실행하려는 경우 : 계속사이트의 Google Apps Script 가젯에서 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));
}
먼저 편집기에서 함수를 실행했지만 오류가 발생했습니다. 내 사이트에 가젯의 UI가 표시되어 스크립트가 이미 게시 된 것 같습니다. oauth 코드를 호출하지 않는 한 작동합니다. – jankeir