Created
September 16, 2015 01:09
-
-
Save woodwardtw/02f14ab1d6465bf53bc6 to your computer and use it in GitHub Desktop.
Not looping but grabs 40 rather than 20 instagram items
This file contains hidden or 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 addTitles() { | |
var sheet = SpreadsheetApp.getActiveSheet(); | |
// sets up the header row for the sheet | |
sheet.appendRow(['User Name', 'Likes Count', 'Comment Count', 'URL', 'Caption', 'Filter', 'Created Time']); | |
} | |
// attempt to loop to get next_url | |
var search = 'dog'; // search term | |
var client_id = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; | |
var url = 'https://api.instagram.com/v1/tags/' + search + '/media/recent?client_id=' + client_id; // replace this with your API client ID | |
function getInstagramData(searchTerm) { | |
var result = UrlFetchApp.fetch(url); | |
var json = JSON.parse(result.getContentText()); | |
var grams = json.data; | |
var next_url = json.pagination.next_url | |
var resultb = UrlFetchApp.fetch(next_url); | |
var jsonb = JSON.parse(resultb.getContentText()); | |
var gramsb = jsonb.data; | |
//Logger.log(result); | |
//Logger.log(next_url); | |
// Instagram gives you 20 on the first request | |
for (var i = 0; i <= 20; i++) { | |
logGram_(grams[i]); | |
logGram_(gramsb[i]); | |
} | |
} | |
function logGram_(gram) { | |
var log = []; | |
// pushes the various elements into the spreadsheet | |
log.push(gram.user.username); | |
log.push(gram.likes.count); | |
log.push(gram.comments.count); | |
log.push(gram.link); | |
log.push(gram.caption.text); | |
log.push(gram.filter); | |
log.push(gram.created_time); | |
SpreadsheetApp.getActiveSheet().appendRow(log) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment