Skip to content

Instantly share code, notes, and snippets.

@nucab
Forked from tomcritchlow/Google Docs Script
Created October 21, 2016 05:40
Show Gist options
  • Save nucab/b7983d0a556994c482069f87fdd96eac to your computer and use it in GitHub Desktop.
Save nucab/b7983d0a556994c482069f87fdd96eac to your computer and use it in GitHub Desktop.
The Google Spreadsheets Script Used To Call Social Media APIs
function FBshares(url) {
var jsondata = UrlFetchApp.fetch("http://graph.facebook.com/"+url);
var object = Utilities.jsonParse(jsondata.getContentText());
return object.shares;
}
function Tweets(url) {
var jsondata = UrlFetchApp.fetch("http://urls.api.twitter.com/1/urls/count.json?url="+url);
var object = Utilities.jsonParse(jsondata.getContentText());
return object.count;
}
function Linkedin(url) {
var jsondata = UrlFetchApp.fetch("http://www.linkedin.com/cws/share-count?url="+url);
return jsondata.getContentText();
}
function SU(url) {
var jsondata = UrlFetchApp.fetch("http://www.stumbleupon.com/services/1.01/badge.getinfo?url="+url);
var object = Utilities.jsonParse(jsondata.getContentText());
return object.result.views;
}
function Gbuzz(url) {
var jsondata = UrlFetchApp.fetch("https://www.googleapis.com/buzz/v1/activities/count?alt=json&url="+url);
var object = Utilities.jsonParse(jsondata.getContentText());
return jsondata.getContentText();
}
function delicious(url) {
var jsondata = UrlFetchApp.fetch("http://feeds.delicious.com/v2/json/urlinfo/data?url="+url);
return jsondata.getContentText();
}
function reddit(url) {
var jsondata = UrlFetchApp.fetch("http://www.reddit.com/api/info.json?url="+url);
var object = Utilities.jsonParse(jsondata.getContentText());
var count = 0;
var forloop = 0;
for (var i in object.data.children) {
count = count + object.data.children[forloop].data.score;
forloop = forloop + 1;
}
return count;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment