Skip to content

Instantly share code, notes, and snippets.

@calvintennant
Last active Dec 16, 2015
Embed
What would you like to do?
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