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数组作为文档&我正在使用出口格式作为docs....So,请给出一些建议,这个代码.....当我运行此代码时,它显示错误: error 302..Moved temporarily..
发布于 2012-09-25 22:21:31
试试这个:
for(var i in entry){
var tempDoc = {};
for(var j in entry[i]){
tempDoc.id = entry[i].id.$t.split('%3A')[1];
}
//now your splitting your string nicely but you also want to use that
docs.push(tempDoc.id);
}
var url='https://docs.google.com/feeds/download/documents/Export?docID='+docs[0]+'&exportFormat=docs'
//you dont want to use the fetch arguments anymore you have authenticated already
UrlFetchApp.fetch(url)好吧,祝你好运,
托马斯·范·拉塔姆
https://stackoverflow.com/questions/12577772
复制相似问题