2014-06-17 29 views
0

我試圖將一張PDF的附件附加到一封電子郵件中,並已將其與下面的代碼一起使用。問題是它必須從編輯器第一次運行,或者授權模式不會出現,腳本只是掛起。我需要能夠從工作表本身運行這個腳本。這裏是我的代碼:谷歌腳本將不會要求授權,除非它在腳本編輯器中運行

function spreadsheetToPDF(key, id, name) { 

    var oauthConfig = UrlFetchApp.addOAuthService("spreadsheets"); 
    var scope = "https://spreadsheets.google.com/feeds" 

    oauthConfig.setConsumerKey("anonymous"); 
    oauthConfig.setConsumerSecret("anonymous"); 
    oauthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope="+scope); 
    oauthConfig.setAuthorizationUrl("https://accounts.google.com/OAuthAuthorizeToken");  
    oauthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken"); 

    var requestData = { 
    "oAuthServiceName": "spreadsheets", 
    "oAuthUseToken": "always", 
    }; 
    var pdf = UrlFetchApp.fetch("https://docs.google.com/a/propertysolutions.com/spreadsheets/d/"+key+ "/export?format=pdf&size=0&fzr=true&portrait=false&fitw=true&gid=" + id + 
       "&gridlines=false&printtitle=false&sheetnames=false&pagenum=UNDEFINED&attachment=true", requestData).getBlob().setName(name); 

    return pdf; 
} 

回答

0

這個問題已經討論了好幾次,它可以在issue tracker under ref 677被發現和最新的更新提的是它不會被固定。與此同時,最新發布的其中一篇文章(由E. Koleda撰寫)提出了一個不同的工作流程(並承諾在不久的將來會展示實例)。

相關問題