Skip to content

Instantly share code, notes, and snippets.

@calvinte
Last active December 16, 2015 01:19
Show Gist options
  • Save calvinte/5354310 to your computer and use it in GitHub Desktop.
Save calvinte/5354310 to your computer and use it in GitHub Desktop.
Alakazam images!
alakazamPage = 1;
function alakazam(magic) {
var params = {
feature: 'popular',
consumer_key: '47HixZoC9snmw0OoJ6pHnky64gJ3WRBtx1IS3gRV',
callback: 'callback',
image_size: 3,
page: alakazamPage
},
uriParams = '',
url = '';
for (paramName in params) {
uriParams += '&' + paramName + '=' + params[paramName];
}
var url = 'https://api.500px.com/v1/' + 'photos.jsonp' + '?' + uriParams;
// Construct JSONP request
tag = document.createElement('script');
tag.src = url;
document.body.appendChild(tag);
callback = function (e) {
for (i = 0; i < e.photos.length; i++) {
var img = document.createElement('img');
img.src = e.photos[i].image_url;
document.body.appendChild(img);
}
if (magic) magic();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment