You'll find a function that generates and saves PDFs for one or all of your sheets in
Convert all sheets to PDF with Google Apps Script.
For anyone who hadn't seen the notice posted in the cellar of the Local Planning Office 3 years ago, Google has deprecated OAuth1 & OAuth1a authorization for their services.
In their guide, Migrating from OAuthConfig to the OAuth1 library, the Apps Script team describes how to migrate your code from one to the other. What they fail to mention is that you don't need to.
There IS an easier way, at least for accessing Google's services.
You can obtain the OAuth 2.0 access token for the current user with ScriptApp.getOAuthToken()
, which means a simplifying change in any script that previously used OAuthConfig.
To convert your script:
Replace
var request = {
"method": "GET",
"oAuthServiceName": "google",
"oAuthUseToken": "always",
"muteHttpExceptions": true
};
with
var request = {
"method": "GET",
headers: {
'Authorization': 'Bearer ' + ScriptApp.getOAuthToken()
},
"muteHttpExceptions": true
};
Delete every remaining reference to the old OAuthConfig class.
...
var oauthConfig = UrlFetchApp.addOAuthService("google");
var scope = "https://docs.google.com/feeds/";
//make OAuth connection
oauthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");
oauthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope="+scope);
oauthConfig.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken");
oauthConfig.setConsumerKey("anonymous");
oauthConfig.setConsumerSecret("anonymous");
...
That's all there is to it.
Follow the migration guide if you're using an external (non-Google) service that requires OAuth 2.0 authentication.
And yes, even with the library it's more complicated than OAuth1 was - but necessarily so.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…