Created
February 1, 2013 00:28
-
-
Save soundTricker/4688073 to your computer and use it in GitHub Desktop.
Convert Google Docs 2 Html on Google Apps Script
GASでGoogle DocumentのファイルをHTMLに変換します。
This file contains 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