获取域列表并查询每个域的特定数据 Google Search Console 和 Nodejs

问题描述

我想出了一种从谷歌搜索控制台域获取数据的方法,但我需要获取多个域并查询每个域以获取以下类型的数据

  • 达到
  • 印象
  • 点击次数
  • 点击率 -平均。搜索位置(如果有)

目前,我得到了但不是平均搜索位置(是否有可能得到这个?)

  {
      keys: [Array],clicks: 10,impressions: 1052,ctr: 0.009505703422053232,position: 5.771863117870723
    },

以上仅针对一个网站/域,如何查询多个域?并从每个人那里获取上述查询数据?如果可能的话,有人可以指出我正确的方向吗?

我的代码

const express = require("express");
const morgan = require("morgan");
const {google} = require('googleapis');
const webmasters = google.webmasters('v3');
const  searchconsole = google.searchconsole({version: 'v1',});

require("dotenv").config();
const app = express();
// middlewares
app.use(morgan("dev"));


  async function main() {
   const auth = new google.auth.GoogleAuth({
    keyFilename: 'AuthFile.json',scopes: [
    'https://www.googleapis.com/auth/webmasters','https://www.googleapis.com/auth/webmasters.readonly',],});

    // Acquire an auth client,and bind it to all future calls
    const authClient = await auth.getClient();
    google.options({auth: authClient});
 
    // Do the magic
    const res = await webmasters.searchanalytics.query({
      // The site URL,including protocol. For example: `http://www.example.com/`.
      siteUrl:'singeleDomainNameHere',// Request body Metadata
      requestBody: {
        // request body parameters
        "startDate": "2015-04-01","endDate": "2021-05-31","dimensions":["country","device","page",]
  
      },});
    console.log(res.data);
 

 
  main().catch(e => {
    console.error(e);
    throw e;
  });




// port
const port = process.env.PORT || 8000;

app.listen(port,() => console.log(`Server is running on port ${port}`));

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)