0

ドキュメントのコンテンツを取得するのに問題があります。ドキュメント ID は取得できましたが、ドキュメントのテキストを取得できませんでした。これには次のコードを使用しています。

function getDocuments(user){
  var scope = 'https://docs.google.com/feeds/';
  //oAuth
  user="email-id"
  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);
    //Logger.log(docs[i])
  }


  var url='https://docs.google.com/feeds/download/documents/Export?docID=?'

  var data=UrlFetchApp.fetch(url,fetchArgs).getAs('text/html').getDataAsString()
  MailApp.sendEmail("email","","",{htmlBody:data})
}

//--------------------------------------------------------------------------------------
//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"};
}

ドキュメントのhtml形式を返しますが、ドキュメントのコンテンツを返すことができませんでした。できるだけ早く私に提案を共有してください..

4

2 に答える 2

2

ドキュメントをメールの HTML 本文にしたい場合は、次のコードを使用できます。

    var id = 'the ID of your document'
    var bodytext = DocumentApp.openById(id).getText();//the text content of your doc (optional)
    var url = 'https://docs.google.com/feeds/';
    var doc = UrlFetchApp.fetch(url+'download/documents/Export?exportFormat=html&format=html&id='+id,
    googleOAuth_('docs',url)).getContentText(); 


    MailApp.sendEmail(destination email, subject, bodytext, {htmlBody:doc});

および OAuth 関数:

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('anonymous');
  oAuthConfig.setConsumerSecret('anonymous');
  return {oAuthServiceName:name, oAuthUseToken:"always"};
}
于 2012-09-25T16:38:08.970 に答える
0

今のところファイルの内容を取得できる関数は知りませんが、ファイル共有リンクでドキュメントを参照できます。

お役に立てれば幸いです!

于 2012-09-25T12:19:25.193 に答える