Skip to content

Instantly share code, notes, and snippets.

@tomcritchlow
Created May 5, 2015 20:41
Show Gist options
  • Save tomcritchlow/cd369e300bb0a6f4ae2b to your computer and use it in GitHub Desktop.
Save tomcritchlow/cd369e300bb0a6f4ae2b to your computer and use it in GitHub Desktop.
function fetchInsta() {
var lat = ;
var long = ;
var apikey = ;
var url = "https://api.instagram.com/v1/media/search?lat="+lat+"&lng="+long+"&distance=400&access_token="+apikey+"&count=100";
Logger.log(url);
var result = UrlFetchApp.fetch(url);
var json = JSON.parse(result.getContentText());
Logger.log(json);
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var existingids = sheet.getDataRange().getValues();
for(i in json.data){
var match = false;
for(j in existingids){
if(json.data[i].id === existingids[j][3].toString()){
var match = true;
}
}
if(match != true){
var image = json.data[i].images.standard_resolution.url;
var username = json.data[i].user.username;
var link = json.data[i].link;
var imageid = json.data[i].id;
var date = json.data[i].created_time;
sheet.appendRow([image,username,link,imageid,date]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment