Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruffrey/0baf592bc27a6de2a153 to your computer and use it in GitHub Desktop.
Save ruffrey/0baf592bc27a6de2a153 to your computer and use it in GitHub Desktop.
Example of doing an image search on getty images and doing something with the first result
var API_KEY_NOT_SECRET = 'insert here';
var xhr = new XMLHttpRequest();
xhr.onload = function () {
console.log('response', JSON.parse(xhr.responseText));
var img = document.createElement('img');
img.src = JSON.parse(xhr.responseText).images[0].display_sizes[0].uri;
document.getElementsByTagName('body')[0].appendChild(img);
};
xhr.onerror = function (e) { console.error(e); };
xhr.open('GET', 'https://api.gettyimages.com/v3/search/images?phrase=milk');
xhr.setRequestHeader('Api-Key', API_KEY_NOT_SECRET);
xhr.send();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment