Skip to content

Instantly share code, notes, and snippets.

@knewjade
Last active June 4, 2017 13:01
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 knewjade/8ab67eaf2c4b532da0c9c6eaa2d58b3a to your computer and use it in GitHub Desktop.
Save knewjade/8ab67eaf2c4b532da0c9c6eaa2d58b3a to your computer and use it in GitHub Desktop.
ランダムなコメントとURLを選択してIFTTTを経由してツイートするGoogle Apps Script
// スプレッドシート A列にコメント・B列に投稿する画像のURLをセットで記載
// 画像のURLはアクセスできればなんでも良い。たとえば http://qiita.com/arribux/items/0394968fa318d9309d33
// IFTTTには Maker Webhooks -> twitter で連携する。開発用トークンは必要なし
function myFunction() {
var spreadsheet = SpreadsheetApp.getActive();
var sheet = spreadsheet.getSheets()[0];
var maxRow = sheet.getDataRange().getLastRow(); // 最終行の番号
var index = Math.floor(Math.random() * maxRow) + 1; // ランダムな番号を取得。indexは1から開始
var comment = sheet.getRange(index, 1).getValue(); // A列からコメントを取得
var figurl = sheet.getRange(index, 2).getValue(); // B列から画像のURLを選択
Logger.log(figurl);
var payload = {
value1: comment,
value2: figurl
};
var options = {
method: "post",
payload: payload,
muteHttpExceptions: true
};
var webhookurl = "https://maker.ifttt.com/trigger/figtw/with/key/***************"; // IFTTTのMakerのURL
var response = UrlFetchApp.fetch(webhookurl, options); // IFTTTの発火
Logger.log(response);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment