Skip to content

Instantly share code, notes, and snippets.

@rilysh
Created October 6, 2021 09:21
Show Gist options
  • Save rilysh/e253074bb7e98c17c55309b533bcbb43 to your computer and use it in GitHub Desktop.
Save rilysh/e253074bb7e98c17c55309b533bcbb43 to your computer and use it in GitHub Desktop.
const fetch = require('node-fetch');
async function getImgur(apiKey, term) {
if (!apiKey) throw new Error('Requires API key.');
if (!term) throw new Error('`Requirres query name.');
try {
await fetch(`https://api.imgur.com/3/gallery/search/top/1/?q=${term}`, {
headers: {
Authorization: `Client-ID ${apiKey}`
}
})
.then(r => r.json())
.then(j => console.log(j))
.catch(e => console.log(e));
} catch (e) {
console.log(e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment