Skip to content

Instantly share code, notes, and snippets.

@soundTricker
soundTricker / GASでGASのコードをダウンロード
Created June 21, 2013 03:33
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);
@soundTricker
soundTricker / sample.js
Created June 18, 2013 04:14
gas-github library sample code. Please see https://github.com/soundTricker/gas-github
/**
* gas-github library sample codes.
* see https://github.com/soundTricker/gas-github
*/
//Create new gist
function createOrUpdateGist(){
//Create Gist API
var gistApi = Github.create(UserProperties.getProperty("githubApiKey")).gists();
@soundTricker
soundTricker / getSpreadsheetComments.js
Last active October 15, 2017 07:42
Get Spreadsheet Comments
var apiKey = "Your API KEY";
function myFunction() {
var option = googleOAuth_();
option.method = "get";
//Spreadsheet.getActive().getId()をそのまま使うと、エラーになるので一回DriveのFileにかえてからIDを取得
var res = UrlFetchApp.fetch("https://www.googleapis.com/drive/v2/files/"+ DriveApp.getFileById(SpreadsheetApp.getActive().getId()).getId() +"/comments?key=" + apiKey , option);
var json = JSON.parse(res.getContentText());
Logger.log(json)
@soundTricker
soundTricker / datastore.js
Created May 17, 2013 11:02
Google Apps ScriptからCloud Datastore APIへのクエリ
function myFunction() {
var option = googleOAuth_();
option.method = "post";
option.contentType = 'application/json';
option.payload = JSON.stringify({
"query":
{
"kinds":
[
@soundTricker
soundTricker / formの作成
Created May 15, 2013 04:31
I/O 2013のGoogle Apps Script Update その1 Form上のGASとFormApp ref: http://qiita.com/items/42266e56c0212ce6b997
function createNewForm() {
var form = FormApp.create('フォームのタイトル');
}
@soundTricker
soundTricker / writeSpreadsheetDataAsCsv.js
Last active December 16, 2015 06:39
SpreadsheetからDriveへデータの書き込み(Date型データのフォーマット付き)
function writeSpreadsheetDataAsCsv() {
//Spreadsheetからデータ取得
var data = SpreadsheetApp.openById('id').getSheetByName('sheetName').getDataRange().getValues();
//二次配列→カンマ区切り文字列の一次配列
var writeDataArray = [];
for(var r = 0; r < data.length; r++) {
var row = data[r];
@soundTricker
soundTricker / convertDocs2Html.js
Created February 1, 2013 00:28
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');
@soundTricker
soundTricker / convert2Spreadsheet.js
Last active July 28, 2019 08:29
Convert from excel file to Sheets on Google Apps Script. GASでExcelファイルをSpreadsheet形式に変換します。
var KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; //developer key , get on https://code.google.com/apis/console/ and set enable the Drive API.
/**
* Convert from Excel data to Spreadsheet
* @param {Blob} excelFile the excel blob data.
* @param {String} filename file name on uploading drive
* @return {Spreadsheet} spreadsheet instance.
**/
function convert2Spreadsheet(excelFile, filename) {
var oauthConfig = UrlFetchApp.addOAuthService('drive');
@soundTricker
soundTricker / github_ranking.js
Created June 22, 2012 12:31
#ajn21のスクリプト
function BigQueryLiveDemo() {
//6219749
var list = BigQuery.Projects.list();
Logger.log(list);
//プロジェクトIDの取得
var projectId = list.getProjects()[0].getId();
@soundTricker
soundTricker / gas.js
Created June 18, 2012 02:39
Google Apps Script GroupsManager and NicknameManager
function グループ() {
// {ユーザ名}@{ドメイン名}のユーザ名の部分を指定
var user = UserManager.getUser("k-ohashi");
//全グループの取得
var groups = GroupsManager.getAllGroups();
for(var i = 0; i < groups.length; i++) {
Logger.log(groups[i].getName());
}