2012-09-25 2 views
0

문서의 내용을 가져 오는 데 문제가 있습니다. 문서 ID를 가져올 수는 있지만 문서의 텍스트를 가져올 수 없습니다. 나는이에 대해 다음 코드를 사용하고 있습니다 : 그것은 문서의 HTML 형식을 반환하지만Google Apps에서 Google 문서의 콘텐츠를 가져 오는 방법은 무엇인가요?

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

, 문서의 내용을 반환 할 수 없습니다. 제발 나에게 어떤 제안을 최대한 빨리 공유하십시오 ..

+0

을 내용? UI에 표시 하시겠습니까? 우편으로 보내시겠습니까? 또한 전체 형식이나 텍스트 만 원하십니까? –

+0

Google 클라우드 저장소에 저장하고 싶습니다. 문서의 전체 형식을 원한다. –

답변

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

지금까지 파일의 내용을 얻을 수있는 기능을 모르겠다, 당신은 파일 공유 링크와 함께 문서를 참조 할 수 있습니다.

당신을 도울 수 있기를 바랍니다.

관련 문제