Hi,
I am making requests to Instagram to pass me back the users recent photo's. This is my code:
function fetchData(pictureView, mainView) { var userid = ''; userid = apiData.url.substring(apiData.url.indexOf('access_token=')); userid = userid.substring(userid.indexOf('=')); myArray = userid.split('.'); userid = myArray[0].substr(1); Ti.API.info(userid); var urlToSend = apiData.request_url + 'users/' + userid + '/media/recent/?access_token=' + apiData.access_token; var views = []; var xhr = Ti.Network.createHTTPClient({ onload: function(e) { // this just gets the first image, need to loop around the data array - TODO var parsedData = JSON.parse(this.responseText); var url = parsedData.data[1].images.standard_resolution.url; // holds image for (var i = 0; i < 1; i++) { // this needs changing to amount of images in JSON var instagramImage = Ti.UI.createImageView({ image: url, //'/images/Tshirt Style/' + images[i], top: 0, left: 0, width: 'auto', height: 'auto', }); views.push(instagramImage); } var scrollview = Ti.UI.createScrollableView({ views: views, width: '200dp', top: '100dp', right: '60dp', bottom: '170dp', left: '60dp',showPagingControl:false,pagingControlColor:'black' }); mainView.add(scrollview); return; }, onerror: function(e) { Ti.API.debug(e.error); alert('Timed out'); }, timeout:10000 }); xhr.open("GET", urlToSend); xhr.send(); }The parsedData is the JSON returned back from Instagram, but, this seems to get returned from one to up to four times, thus onload being called more than once, can anybody see the reason? What I'm trying to do, is put the images url from the JSON returned from Instagram into the scrollview.
Hope this makes sense?!
Regards, Steve
1 Answer
Accepted Answer
you need to stop the webView from loading as soon as you get the access token.
what does stop loading do? It needs to remove the eventListener
Your Answer
Think you can help? Login to answer this question!