我正在运行以下代码。它说
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!!
答案 0 :(得分:0)
我可以与UrlFetchApp.fetch()
分享我目前的经验在今天之前,我的脚本(在几张纸上)工作正常,但今天却出错了。经过一些修修补补后,我通过在网址中将https更改为http来重新运行。
这可能是你的问题的巧合,我不会声称知道,但我发帖以防万一。
(在我的情况下,,错误报告为:
[意外错误:https:// theURLcalled ...(第44行)]
其中第44行是代码
var response = UrlFetchApp.fetch(url)
答案 1 :(得分: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