Last active
May 11, 2021 02:26
-
-
Save grant/5e669a28957245f7ae83de650d8ad440 to your computer and use it in GitHub Desktop.
gapi script
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
// 1. Load the JavaScript client library. | |
gapi.load('client', init); | |
async function init() { | |
// 2. Initialize the JavaScript client library. | |
await gapi.client.init({ | |
discoveryDocs: ['https://discovery.googleapis.com/$discovery/rest'] | |
}); | |
start(); | |
} | |
const API_QUERY = 'android'; | |
async function start() { | |
try { | |
// 3. Make the API request. | |
const apiRequest = await gapi.client.discovery.apis.list(); | |
const result = JSON.parse(apiRequest.body); | |
// 4. Log the results of the API request | |
const androidAPIs = result.items.filter(api => api.id.startsWith(API_QUERY)); | |
const androidAPITitles = androidAPIs.map(api => api.title); | |
const uniqueAndroidAPITitles = [...new Set(androidAPITitles).values()]; | |
document.getElementById('result').innerHTML = | |
`${uniqueAndroidAPITitles.length} APIs:<br>${uniqueAndroidAPITitles.join('<br/> ')}`; | |
} catch (e) { | |
console.error(e); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment