Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
twitter-to-spreadsheet.js
var getTwitterService = function() {
return OAuth1.createService("Twitter")
.setAccessTokenUrl("https://api.twitter.com/oauth/access_token")
.setRequestTokenUrl("https://api.twitter.com/oauth/request_token")
.setAuthorizationUrl("https://api.twitter.com/oauth/authorize")
.setConsumerKey("コンシューマーキー")
.setConsumerSecret("コンシューマーシークレット")
.setAccessToken("アクセストークン", "アクセストークンシークレット");
};
function main() {
var service = getTwitterService();
var res = service.fetch("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=hololivetv");
return res;
}
function doGet() {
//スプレッドシートのIDは、https://docs.google.com/spreadsheets/d/(spread sheet ID)[/editとかあるかもだがそこは捨てる]で表される
var spreadsheet = SpreadsheetApp.openById("スプレッドシートのID");
var sheet = spreadsheet.getSheetByName("sheet1");
var jsonData = JSON.parse(main());
var x = 1;
for (var i = 0; i < jsonData.length; i++) {
var text = jsonData[i]["text"];
var textArray = text.split(/\r\n|\r|\n/);
for (var n = 0; n < textArray.length; n++) {
var target = textArray[n];
var m = target.match(/^([0-9]{1,2}:[0-9]{2})(~|〜)(.+)$/);
if (m) {
sheet.getRange("B" + x).setValue(m[1]);
sheet.getRange("A" + x).setValue(m[3]);
x++;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.