开发者

Google Apps Script UrlFetchApp Exception

Im 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 what I currently have:

function createPdf(){

  var ss = SpreadsheetApp.getActiveSpreadsheet();

  var oauthConfig = UrlFetchApp.addOAuthService("google");
  oauthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");
  oauthConfig.setR开发者_运维百科equestTokenUrl("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;

}

When debugging the script, I get the following error:

Unexpected exception upon serializing continuation

Any help would be appreciated.


After some further digging, I found this solution:

function createPdf(){

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var pdf = ss.getAs("application/pdf");
  var file = DocsList.createFile(pdf);
  file.rename("Test");

  return file;

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜