-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiscover_api.js
33 lines (29 loc) · 1.03 KB
/
discover_api.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const { google } = require('googleapis')
const moment = require('moment-timezone');
const _ = require("lodash");
const getGSC = async () => {
let from = moment().subtract(9, 'days').tz('America/Los_Angeles').format("YYYY-MM-DD")
let to = moment().subtract(2, 'days').tz('America/Los_Angeles').format("YYYY-MM-DD")
console.log(from)
console.log(to)
const auth = await google.auth.getClient({ scopes: ['https://www.googleapis.com/auth/webmasters']})
const gsc = await google.searchconsole({ version: 'v1', auth });
let rows = []
try {
const res = await gsc.searchanalytics.query({
siteUrl: "https://www.blick.ch",
requestBody: {
startDate: from,
endDate: to,
dimensions: ["page"],
type: "discover"
}
})
rows = rows.concat(res.data.rows)
} catch (error) {
console.log("Search API error")
}
rows = _.orderBy( rows, 'impressions', "desc");
console.log(rows)
};
getGSC()