I am trying to set up a chron job to connect to the instagram API, grab 'my feed' and download the images. I cannot get past the OAuth 2.0 step. I have already looked at a number of resources including:
How to authorize with oauth 2.0 from appscript to Google APIs? - methods are deprecated and I cannot get the pop up to for the oauth to show up.
https://code.google.com/p/google-apps-script-issues/issues/detail?id=2580 and all the links that follow in the discussion. I cannot figure out how to apply this to work without an html page.
http://www.googleappsscript.org/home/downloading-instagram-photos-to-your-google-drive-using-google-apps-script works well for hash tags, but I would like to be able to get the feed from my user account.
Any help would be greatly appreciated, this is the best I have been able to figure out, if I could get the pop up to work I would be good to go, but I cannot.
function startInstagram () {
var redurl = getCallbackURL(getInstagram);
var consumerKey = '#######';
var consumerSecret = '#######';
var parameters = {
method : 'post',
payload:
'grant_type=authorization_code'+'&client_id='+consumerKey+'&client_secret='+consumerSecret+'&grant_type=authorization_code&redirect_uri='+redurl+'&response_type=token'
};
var token = UrlFetchApp.fetch('https://api.instagram.com/oauth/authorize/', parameters).getContentText();
Logger.log(['token', token]);
}
function getInstagram (vars) {
var res = {};
Logger.log(['get', vars]);
return;
}
function getCallbackURL(callbackFunction) {
var scriptUrl = 'https://script.google.com/d/<ID>';
var urlSuffix = '/usercallback?state=';
var stateToken = ScriptApp.newStateToken()
.withMethod(callbackFunction)
.withTimeout(60*10*5)
.createToken();
return scriptUrl + urlSuffix + stateToken;
}