【发布时间】:2015-06-02 02:52:29
【问题描述】:
function topdf() {
var foldersave=DriveApp.getFolderById('0Byy1DdsfdfTQRnVlfb05wOV83T00')
var d= new Date()
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");
//get request
var request = {
"method": "GET",
"oAuthServiceName": "google",
"oAuthUseToken": "always",
"muteHttpExceptions": true
};
var key='1QUj_OyHisdfsdfjwfNu1l-JuI528ev6FNRJv-oljIY';
var fetch='https://docs.google.com/spreadsheets/d/'+key+'/export?format=pdf&size=A4&portrait=false'
var name = "Timestamp for: "+ d + ".pdf";
var pdf = UrlFetchApp.fetch(fetch, request);
pdf = pdf.getBlob().setName(name);
var file = foldersave.createFile(pdf)
}
我正在寻找使用 OAuth2 转换上述代码的分步教程。我在迁移时遇到了一些问题。我可以在 OAuth2 上找到一些代码,但不知道它是如何联系在一起的。之前的代码很简单,现在好像复杂了很多?还是我错过了一些简单的东西?
我尝试更换 OAuth 连接部分,但遇到了问题。 https://github.com/googlesamples/apps-script-oauth2 似乎应该以某种方式使用getDriveService?
【问题讨论】:
标签: pdf google-apps-script google-sheets