0

我看到有几篇关于“无法设置属性”的帖子,我仍在努力找出我在这里缺少的东西。我是 Javascript 和 GAS 的新手。我一直在写一本关于 GAS 的书,名为《GScript 企业应用程序要点》。这段代码来自这本书,我没有成功。它表示运行它两次,并且在某一时刻确实提示了授权,这只发生了一次,我在此之前和之后都看到过这个错误。任何人都可以建议一个资源或我可以咨询的东西来帮助解决它..或者更好地理解错误?谢谢!!

代码

/*
* Private for OAuth
* @ returns OAuth headers
*/
DOCS_LIST_API.googleOAuth = function() {
  var oAuthConfig = UrlFetchApp.addOAuthService("google");
oAuthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken? scope=https://docs.google.com/feeds/");
oAuthConfig.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken");
oAuthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");
oAuthConfig.setConsumerKey('anonymous');
oAuthConfig.setConsumerSecret('anonymous');
return {oAuthServiceName:'google', oAuthUseToken:"always"};
}

var DOCS_LIST_API = {};


/*
* @ args docID String the id for a Google Document
* @ args format String can be, "txt", "odt", "pdf", "html", "rtf", "doc", "png",
"zip"
* @ returns blob
*
*/
DOCS_LIST_API.GdocToFormat = function(docID, format){
var fetchArgs = DOCS_LIST_API.googleOAuth;
fetchArgs.headers = { "GData-Version": "3.0" };
fetchArgs.method = 'get';
var url = 'https://docs.google.com/feeds/download/documents/export/Export?id='+
   docID+'&exportFormat='+format+'&format='+format;
 return UrlFetchApp.fetch(url, fetchArgs);
 }

 // Run it twice
 function doOAuth(){
  try{
    DOCS_LIST_API.GdocToFormat();
     }catch(e){
   }
 }
4

1 回答 1

2

DOCS_LIST_API您会收到错误消息,因为您在将其声明为变量之前尝试设置 的属性。

移动var DOCS_LIST_API = {};到顶部。

于 2012-06-21T23:40:11.743 回答