-
-
Save labnol/1907313 to your computer and use it in GitHub Desktop.
Google Apps Script to set cell comment to latest Tweet
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
function setComments() { | |
var ss = SpreadsheetApp.getActiveSpreadsheet(); | |
var twitterDataRange = ss.getRangeByName("Twitter3"); | |
vals = twitterDataRange.getValues(); | |
for (i in vals) { | |
var row = vals[i]; | |
for (j in row) { | |
var col = vals[i][j]; | |
if (col.length > 0) { | |
vals[i][j] = fetchTweet(col.substr(1)); | |
} | |
} | |
} | |
twitterDataRange.setComments(vals); | |
} | |
function fetchTweet(screenName) { | |
var oAuthConfig = UrlFetchApp.addOAuthService("twitter"); | |
oAuthConfig.setAccessTokenUrl("https://api.twitter.com/oauth/access_token"); | |
oAuthConfig.setRequestTokenUrl("https://api.twitter.com/oauth/request_token"); | |
oAuthConfig.setAuthorizationUrl("https://api.twitter.com/oauth/authorize"); | |
oAuthConfig.setConsumerKey(ScriptProperties.getProperty("twitterConsumerKey")); | |
oAuthConfig.setConsumerSecret(ScriptProperties.getProperty("twitterConsumerSecret")); | |
var options = | |
{ | |
"oAuthServiceName" : "twitter", | |
"oAuthUseToken" : "always" | |
}; | |
var requrl = "https://api.twitter.com/1/statuses/user_timeline.json?include_entities=false&include_rts=true&screen_name=" + screenName + "&count=1"; | |
var result = UrlFetchApp.fetch(requrl, options); | |
var o = Utilities.jsonParse(result.getContentText()); | |
return o[0].text; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment