Skip to content

Instantly share code, notes, and snippets.

@rock3m
Created March 31, 2022 19:21
Show Gist options
  • Save rock3m/39a2dd662bf3b195db3e42687cf5331f to your computer and use it in GitHub Desktop.
Save rock3m/39a2dd662bf3b195db3e42687cf5331f to your computer and use it in GitHub Desktop.
An Example of Pulling Twitter Followers using Apps Script
var sheetName = "_Example";
var screenName = "imgracehuang";
function populateFollowerCount() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName(sheetName);
var response = fetch("https://cdn.syndication.twimg.com/widgets/followbutton/info.json?screen_names=" + screenName);
var followerCount;
if (response && response[0]) {
followerCount = response[0].followers_count
}
sheet.appendRow([Utilities.formatDate(new Date(), "GMT", "yyyy-MM-dd"), followerCount]);
};
function fetch(url) {
var ignoreError = {
"muteHttpExcecptions": true
};
var source = UrlFetchApp.fetch(url, ignoreError).getContentText();
var data = JSON.parse(source);
return data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment