google-api-nodejs-client icon indicating copy to clipboard operation
google-api-nodejs-client copied to clipboard

Add new properties into google search console without user interactions

Open santhoshsk1918 opened this issue 7 years ago • 3 comments

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

santhoshsk1918 avatar Mar 01 '19 07:03 santhoshsk1918

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();

vishald123 avatar Apr 12 '19 12:04 vishald123

@santhoshsk1918 did using a service account do the trick for you?

bcoe avatar Apr 18 '19 00:04 bcoe

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!

JustinBeckwith avatar Jun 10 '19 19:06 JustinBeckwith