TypeScript typings for Google Search Console API v1
The Search Console API provides access to both Search Console data (verified users only) and to public information on an URL basis (anyone)
For detailed description please check documentation.
Installing
Install typings for Google Search Console API:
npm install @types/gapi.client.searchconsole-v1 --save-dev
Usage
You need to initialize Google API client in your code:
gapi.load('client', () => {
});
Then load api client wrapper:
gapi.client.load(
'https://searchconsole.googleapis.com/$discovery/rest?version=v1',
() => {
}
);
gapi.client.load('searchconsole', 'v1', () => {
});
Don't forget to authenticate your client before sending any request to resources:
var client_id = '',
scope = [
'https://www.googleapis.com/auth/webmasters',
'https://www.googleapis.com/auth/webmasters.readonly',
],
immediate = true;
gapi.auth.authorize(
{client_id: client_id, scope: scope, immediate: immediate},
authResult => {
if (authResult && !authResult.error) {
} else {
}
}
);
After that you can use Google Search Console API resources:
await gapi.client.webmasters.searchanalytics.query({siteUrl: 'siteUrl'});
await gapi.client.webmasters.sitemaps.delete({
feedpath: 'feedpath',
siteUrl: 'siteUrl',
});
await gapi.client.webmasters.sitemaps.get({
feedpath: 'feedpath',
siteUrl: 'siteUrl',
});
await gapi.client.webmasters.sitemaps.list({siteUrl: 'siteUrl'});
await gapi.client.webmasters.sitemaps.submit({
feedpath: 'feedpath',
siteUrl: 'siteUrl',
});
await gapi.client.webmasters.sites.add({siteUrl: 'siteUrl'});
await gapi.client.webmasters.sites.delete({siteUrl: 'siteUrl'});
await gapi.client.webmasters.sites.get({siteUrl: 'siteUrl'});
await gapi.client.webmasters.sites.list({});