【问题标题】:Google Apps Script UrlFetchApp ExceptionGoogle Apps 脚本 UrlFetchApp 异常
【发布时间】:2011-11-26 06:18:04
【问题描述】:

m in the process of creating a custom timesheet using Google Docs and Google Apps Script. One of the requirements is to save the timsheet as a PDF when the user submits the timesheet. Heres 我目前拥有的:

function createPdf(){

  var ss = SpreadsheetApp.getActiveSpreadsheet();

  var oauthConfig = UrlFetchApp.addOAuthService("google");
  oauthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");
  oauthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope=https://spreadsheets.google.com/feeds/");
  oauthConfig.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken");
  oauthConfig.setConsumerKey("anonymous");
  oauthConfig.setConsumerSecret("anonymous");

  var url =  "https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key="
      + ss.getId() +  "&gid=0&portrait=true" +"&exportFormat=pdf";

  var requestData = {
    "oAuthServiceName": "google",
    "oAuthUseToken": "always"
  };

  var result = UrlFetchApp.fetch(url, requestData);
  var content = result.getBlob();
  var file = DocsList.createFile(content);

  return file;

}

调试脚本时出现以下错误:

序列化延续时的意外异常

任何帮助将不胜感激。

【问题讨论】:

    标签: javascript google-apps-script


    【解决方案1】:

    经过进一步挖掘,我找到了这个解决方案:

    function createPdf(){
    
      var ss = SpreadsheetApp.getActiveSpreadsheet();
      var pdf = ss.getAs("application/pdf");
      var file = DocsList.createFile(pdf);
      file.rename("Test");
    
      return file;
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-07
      • 1970-01-01
      • 2017-12-08
      相关资源
      最近更新 更多