Исключение UrlFetchApp скрипта Google Apps - PullRequest
2 голосов
/ 27 сентября 2011

I 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. Here s, что у меня сейчас есть:

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;

}

При отладке скрипта я получаю следующую ошибку:

Неожиданное исключение при продолжении сериализации

Буду признателен за любую помощь.

1 Ответ

3 голосов
/ 29 сентября 2011

После дальнейших раскопок я нашел это решение:

function createPdf(){

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

  return file;

}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...