Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save landsurveyorsunited/cd8fa9f18004908b2bd740b0cf12b045 to your computer and use it in GitHub Desktop.
Save landsurveyorsunited/cd8fa9f18004908b2bd740b0cf12b045 to your computer and use it in GitHub Desktop.
Convert Google Docs 2 Html on Google Apps Script GASでGoogle DocumentのファイルをHTMLに変換します。
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