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