-
-
Save wmakeev/9775641 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; //developer key , get from https://code.google.com/apis/console/b/1/ | |
var FILE_ID = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; // drive file id | |
function convertDocuments2() { | |
var oauthConfig = UrlFetchApp.addOAuthService('drive'); | |
//Create oauth config for drive api | |
var scope = 'https://www.googleapis.com/auth/drive'; | |
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'); | |
//1gC166L6sjPzhKlZB-ux2L7wsqnYn5eZ_bqbe5BjgwSM | |
var param = { | |
method:'get', | |
oAuthServiceName: 'drive', | |
oAuthUseToken: 'always', | |
}; | |
//Get file | |
var res = UrlFetchApp.fetch('https://www.googleapis.com/drive/v2/files/' + FILE_ID + '?fields=exportLinks&key='+KEY, param); | |
//this response body format is json , and it has file id. Please see https://developers.google.com/drive/v2/reference/files#resource | |
var fileDataResponse = JSON.parse(res.getContentText()); | |
var res = UrlFetchApp.fetch(fileDataResponse.exportLinks["text/html"] + "&key=" + KEY,param); | |
return res.getContentText(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment