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 soundTricker/5828620 to your computer and use it in GitHub Desktop.
Save soundTricker/5828620 to your computer and use it in GitHub Desktop.
Google Apps Scriptのプロジェクトのコードを外部からダウンロード/アップロード(ダウンロード編) ref: http://qiita.com/soundTricker@github/items/8873f29781d1e123cfa8
function downloadGASFiles(downloadUrl) {
//Google OAuth用の設定
var oauthConfig = UrlFetchApp.addOAuthService('drive');
var scope = 'https://www.googleapis.com/auth/drive+https://www.googleapis.com/auth/drive.file+https://www.googleapis.com/auth/drive.scripts';
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');
//UrlFetchAppの設定
var options = {
method:'get',
oAuthServiceName: 'drive',
oAuthUseToken: 'always'
};
//ダウンロード
var jsonString = UrlFetchApp.fetch(url,getParams).getContentText();
//JSON形式なのでパース
return JSON.parse(json);
}
function test() {
var gasFiles = downloadGASFiles("ファイルID");
for(var i = 0;i < gasFiles.files.length; i++) {
Logger.log("ファイル名:%s", gasFiles.files[i].name);
Logger.log("コード:%s", gasFiles.files[i].source);
}
}
{
'files':[
{
'id' : 'GASプロジェクト内の多分一意なファイルID',
'name' : 'ファイル名',
'type' : 'ファイルのタイプ server_js:.gs形式のGASのコード html:HtmlServiceで利用するhtml',
'source' : '実際のコード'
}
//プロジェクト内のファイルの数だけ上があります。
]
}
//File idは上とかでよく出てくるScript Editorを開いた時にURLに記載されたID
function getDonwloadLink(fileId) {
return DriveApp.getFileById(fileId).getDownloadUrl();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment