0

我正在运行以下代码。它说

UrlFetchApp.fetch()中的意外错误

function archive(){
 var oauthConfig = UrlFetchApp.addOAuthService("docs");
  oauthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");
  oauthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope=https://docs.google.com/feeds/");
  oauthConfig.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken");
  oauthConfig.setConsumerKey(consumerkey);
  oauthConfig.setConsumerSecret(consumerSecret);

    var requestData = {

    "method": "POST",
    "headers": { "GData-Version": "3.0" },
    "oAuthServiceName": "docs",
       "payload":getPayload(),
    "oAuthUseToken": "always"
  };

 var url='https://docs.google.com/feeds/default/private/archive'
  var result = UrlFetchApp.fetch(url, requestData);

  }
function getPayload() {

var xml='<?xml version="1.0" encoding="UTF-8"?>'+
  '<atom:entry xmlns="http://www.w3.org/2005/Atom" xmlns:docs="http://schemas.google.com/docs/2007">'+
  '<docs:archiveConversion source="application/vnd.google-apps.document" target="application/msword"/>'+
  '<docs:archiveConversion source="application/vnd.google-apps.spreadsheet" target="text/csv"/>'+
  '<docs:archiveConversion source="application/pdf" target="application/pdf"/>'+
  </atom:entry>';
   Logger.log(xml)
   return xml;
  }


If you have another way to do this, please let me know asap.

Thank you in advance!!
4

2 回答 2

0

我可以分享我目前使用 UrlFetchApp.fetch() 的经验

在今天之前,我的脚本(在几张纸上)工作正常,但今天它给出了一个错误。经过一些修补后,我通过将 url 中的 https 更改为 http 来重新运行。

这很可能与您的问题巧合,我不声称知道,但我发布以防万一。

在我的情况下,错误报告为:

[意外错误:https://theURLcalled...(line44)]

其中第 44 行是代码
var response = UrlFetchApp.fetch(url)

于 2012-09-21T15:17:51.857 回答
0

以下示例可能对您有所帮助。这些示例使用 Google OAuth 和 UrlFetch

https://sites.google.com/site/appsscripttutorial/urlfetch-and-oauth/get-the-document-list-of-a-domain-user https://sites.google.com/site/appsscripttutorial/urlfetch -and-oauth/share-docs-between-domain-users https://sites.google.com/site/appsscripttutorial/applications/doodle-for-your-domain

于 2012-09-21T19:19:07.533 回答