Created
March 31, 2022 19:21
-
-
Save rock3m/39a2dd662bf3b195db3e42687cf5331f to your computer and use it in GitHub Desktop.
An Example of Pulling Twitter Followers using Apps Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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