Skip to content

Instantly share code, notes, and snippets.

@paulmason
Last active January 10, 2016 13:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulmason/342e281373e8aa28f380 to your computer and use it in GitHub Desktop.
Save paulmason/342e281373e8aa28f380 to your computer and use it in GitHub Desktop.
Instagram Feed
// Copy the instagramFeed function between the two commented lines
// ...
// mobileMenu(); COPY BELOW THIS LINE
instagramFeed = function() {
var client_id, feed_url, getImages, items_to_load, username;
client_id = 'xxxxxxxxxxxxxxxxxxxxx'; // <-- REPLACE THE X's WITH YOUR CLIENT ID
username = $('.instagram-widget').attr('data-username');
if (username.length < 1) {
return;
}
feed_url = 'https://api.instagram.com/v1/users/296922654/media/recent/?client_id=' + client_id;
items_to_load = 5;
if (!home_widget_twitter_enabled && !home_widget_blog_enabled) {
items_to_load += 6;
$('.instagram-widget .items').addClass('wide');
}
$.ajax({
dataType: "jsonp",
url: 'https://api.instagram.com/v1/users/search?q=' + username + '&client_id=' + client_id,
success: function(response) {}
}).done(function(data) {
var user, user_id, _i, _len, _ref;
user_id = '';
_ref = data.data;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
user = _ref[_i];
if (username === user.username) {
user_id = user.id;
break;
}
}
return getImages(user_id);
});
return getImages = function(user_id) {
return $.ajax({
dataType: "jsonp",
url: 'https://api.instagram.com/v1/users/' + user_id + '/media/recent/?client_id=' + client_id,
success: function(response) {}
}).done(function(data) {
var i, _i, _results;
_results = [];
for (i = _i = 0; 0 <= items_to_load ? _i <= items_to_load : _i >= items_to_load; i = 0 <= items_to_load ? ++_i : --_i) {
_results.push($('.instagram-widget .items').append('<a class="item" target="_blank" href="' + data.data[i].link + '"><img src="' + data.data[i].images.low_resolution.url + '" /></a>'));
}
return _results;
});
};
};
// VideoModal = (function() { COPY ABOVE THIS LINE
// ...
@zanderi
Copy link

zanderi commented Dec 22, 2015

Returns error "The access_token provided is invalid." Will not display anything

@akin-fagbohun
Copy link

This isn't working for me either, although I didn't get an error message - just nothing at all.

I have a recent version of the theme where the client ID can be entered on the back side but that didn't work either.

@akin-fagbohun
Copy link

I have a second store that has the blockshop theme and the instagram feed on that one works fine. I tried lifting the section of code from that 'shop.js' file and deploying it on the site that doesn't function, changing the Instagram Client ID. No Joy... although I did notice that the segment of code from the functional site has a few extra lines of code than the one on the dysfunctional site.

Does that suggest that the problem is less with the Shop.js and more with something else? Some support on this would be fantastic as it's really damaging the final aesthetic of the site. I have also emailed Troop Themes directly but they seem very slow at responding. @zanderi, were you able to resolve your issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment