Add new properties into google search console without user interactions
Hi i have a application which created sub-domains dynamically and when a sub-domain is created i want to add website to google search console and ask google to index this site using sitemap. I am using node.js application and i want to do this in the backend with out any user interations.
const {google} = require('googleapis');
const webmasters = google.webmasters({
version: 'v3',
auth: {MyApiKey},
})
module.exports.getListOfSites = () => {
let listSitesPromise = webmasters.sites.list({});
listSitesPromise.then((resp) => {
console.log(resp);
}).catch((err) => {
console.log(err);
})
};
This give error
401 Login Requried
is there a way to skip authentication and directly add these sites to google search console account.
My whole purpose is to get my sites indexed if there is another method please suggest
Thanks
Hi @santhoshsk1918, You can try using a Service account. Try the following way.
const {google} = require('googleapis');
const SCOPES = ['https://www.googleapis.com/auth/webmasters'];
const key = require('./[YOUR_SERVICE_ACCOUNT_FILE].json');
const jwtClient = new google.auth.JWT(
key.client_email,
null,
key.private_key,
SCOPES,
);
jwtClient.authorize(function (err, token) {
if(err){
console.log(err,'err');
}else{
return
}
});
function list() {
const webmasters = google.webmasters({
version : "v3",
auth : jwtClient
});
let wb = webmasters.sites.list({})
.then(function (res) {
console.log(res);
}).catch(function (err) {
console.log(err);
})
}
list();
@santhoshsk1918 did using a service account do the trick for you?
Greetings folks! We haven't heard anything on this issue for a while, so we're going to go ahead and close it out. Please do let us know if you're still running into issues!