function getDocuments(user){
var scope = 'https://docs.google.com/feeds/';
//oAuth
user="user@yourdomain.com"
var fetchArgs = googleOAuth_('docs', scope);
var url = scope + user+'/private/full?v=3&alt=json';
var urlFetch = UrlFetchApp.fetch(url, fetchArgs);
var json=Utilities.jsonParse(urlFetch.getContentText())
var entry = json.feed.entry;
var docs = [];
for(var i in entry){
var tempDoc = {};
for(var j in entry[i]){
tempDoc.id = entry[i].id.$t.split('%3A')[1];
}
docs.push(tempDoc);
}
var url='https://docs.google.com/feeds/download/documents/Export?docID='+docs[0]+'&exportFormat=docs'
UrlFetchApp.fetch(url,fetchArgs)
}
//--------------------------------------------------------------------------------------
//Google oAuth
//Used by getDocuments(user)
function googleOAuth_(name,scope) {
var oAuthConfig = UrlFetchApp.addOAuthService(name);
oAuthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope="+scope);
oAuthConfig.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken");
oAuthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");
oAuthConfig.setConsumerKey(consumerKey);
oAuthConfig.setConsumerSecret(consumerSecret);
return {oAuthServiceName:name, oAuthUseToken:"always",method:"GET"};
}
我正在尝试通过文档 ID 下载文档的上述代码。我有一个文档 ID 数组作为文档,我正在使用导出格式作为文档......所以请对此代码提出一些建议......当我运行此代码时,它会给出错误:错误 302 ..临时移动。 .