Skip to content

Instantly share code, notes, and snippets.

@grant
Last active May 11, 2021 02:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grant/5e669a28957245f7ae83de650d8ad440 to your computer and use it in GitHub Desktop.
Save grant/5e669a28957245f7ae83de650d8ad440 to your computer and use it in GitHub Desktop.
gapi script
// 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