Created
June 21, 2013 03:33
-
-
Save soundTricker/5828620 to your computer and use it in GitHub Desktop.
Google Apps Scriptのプロジェクトのコードを外部からダウンロード/アップロード(ダウンロード編) ref: http://qiita.com/soundTricker@github/items/8873f29781d1e123cfa8
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
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); | |
} | |
} |
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
{ | |
'files':[ | |
{ | |
'id' : 'GASプロジェクト内の多分一意なファイルID', | |
'name' : 'ファイル名', | |
'type' : 'ファイルのタイプ server_js:.gs形式のGASのコード html:HtmlServiceで利用するhtml', | |
'source' : '実際のコード' | |
} | |
//プロジェクト内のファイルの数だけ上があります。 | |
] | |
} |
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
//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