English 中文(简体)
OAUT可能来自谷歌应用程序文稿工具吗?
原标题:Is OAuth possible from a Google Apps Script gadget on a site?

I have developed a google apps script in a spreadsheet that uses oAuth. I now copied the same script to a gadget that runs on a site. When I want to run the function that uses oauth I get the following error:

连续连续序号的意外例外

This happens both when I run the actual gadget on a site or when I run the function from the script editor. The exact same code works when called from the script editor in the spreadsheet. Am I doing something wrong or is it simply not possible to use oAuth with UrlFetchApp.fetch when using a site gadget?

谢谢

扬( 扬)

这里有一些关于我所要做的事情的样本代码, 你需要包含谷歌 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));
  }
问题回答

只有在从脚本管理器内部运行代码时才显示 OAUT 批准对话框。 为了将 Apps 脚本代码发布到网站, 您需要将脚本的版本发布为服务。 打开该脚本的代码编辑器, 并确保您可以先使用脚本编辑器运行函数。 这将验证您的 OAUT 批准已被存储 。

为什么使用 Oauth 在 Google Apps 脚本用于日历服务?





相关问题
How to use year counter google app script?

I need an urgent help i have data as follows in a google sheet i need to add a year counter to the column d as follows using google apps script

What is the daily email limit in Google Apps Script?

Can someone tell me if there is a webpage that lists the official Google limit (Quotas) on emails sent from a Google Apps Script? In testing my little script I got an error: Service invoked too many ...

Reference Error for property of Javascript Object

I have built an object in Javascript on the Google Apps Script engine and every time I run my script I get a reference error saying uName is not defined. Here is the relivant code: function DataSet()...

Run Google Apps Script on Google-Spreadsheet event?

If I create a Google apps script, can I hook it up to Google spreadsheet to run based on an event, or must I manually invoke it? I don t know if Google Sheets supports any events. For example: a ...

Google gadget/spreadsheet: Grab spreadsheet key for gadget

So I m working on a google gadget(really only gadgetizing so I can get a datastore for this) that I want to be embeddable in a google spreadsheet (after this point, I m going to skip the word google - ...

热门标签