Skip to content

Instantly share code, notes, and snippets.

@soundTricker
soundTricker / calendar.js
Created April 26, 2012 02:10
google apps scriptで直接Google Calendar API(v2)を呼ぶ(Call Google Calendar API with Google Apps Script in direct)
function myFunction() {
//oauth の設定
var oauth = UrlFetchApp.addOAuthService(Session.getActiveUser().getEmail());
oauth.setConsumerKey("anonymous"); //ちゃんとしたのを使ったほうがいいとおもふ
oauth.setConsumerSecret("anonymous"); //ちゃんとしたのを使ったほうがいいとおもふ
oauth.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope=https%3A%2F%2Fwww.google.com%2Fcalendar%2Ffeeds%2F");
oauth.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken");
oauth.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");
@soundTricker
soundTricker / main.js
Created June 12, 2012 05:28
Google Apps 2 legged OAuth of Google Calendar API with Google Apps Script. Please import oauth.js and sha1.js from http://code.google.com/p/oauth/. if you happen any problem,Please modify oauth.js to below oauth.js code.
function twoleggedOAuth() {
var action = "https://www.google.com/calendar/feeds/default/private/full?xoauth_requestor_id={user mail address}";
var accessor = { consumerSecret: '{consumerSecret}' };
var message = { method: 'get', action: action, parameters: {}, };
OAuth.setParameter(message, 'oauth_version', '1.0');
OAuth.setParameter(message, 'oauth_nonce', OAuth.nonce(32));
OAuth.setParameter(message, 'oauth_timestamp', OAuth.timestamp());
OAuth.setParameter(message, 'oauth_consumer_key', '{your domain}');
OAuth.SignatureMethod.sign(message, accessor);
@soundTricker
soundTricker / bigquery.js
Created June 12, 2012 12:20
BiqQuery API with Google Apps Script CheatSheet
var projectId = ScriptProperties.getProperty("projectId");
function プロジェクトの取得() {
var list = BigQuery.Projects.list();
Logger.log(list);
}
@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());
}
@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 / 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 / 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 / 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 / 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 / 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":
[