Created
July 26, 2017 18:50
-
-
Save mkozhukharenko/a873a8d085efa94a3176f53276253c8f to your computer and use it in GitHub Desktop.
Bing API search javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let request = async (query: string): Promise<any[]> => { | |
const myHeaders = new Headers() | |
myHeaders.append('Ocp-Apim-Subscription-Key', 'b5deb0d4be5a4dcaaa478f7b343baa3d') | |
const params = { | |
q: query, | |
safeSearch: 'Strict', | |
license: 'Public' | |
} | |
const urlParams = new URLSearchParams((Object as any).entries(params)) // entries works in Chrome | |
const url = 'https://api.cognitive.microsoft.com/bing/v5.0/images/search?' + urlParams.toString() | |
const res = await fetch(url, { | |
method: 'GET', | |
headers: myHeaders | |
}) | |
const data = await res.json() | |
console.log('Image results from BING: ', data.value) | |
return data.value | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment