-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgoogle-search-console-webproperty-available.js
64 lines (47 loc) · 1.8 KB
/
google-search-console-webproperty-available.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
(page,done) =>
{
var that = this;
let lable = "GSC";
let msg = "";
let type = "info";
let what = null;
let prio = null;
//GSC API
const { googleApiAccessToken } = this.getGlobals();
if(!googleApiAccessToken) {done();return null; }
let url = page.getURL('first');
let uo = new URL(url);
let origin = uo.origin+'/';
let api = 'https://www.googleapis.com/webmasters/v3/sites/'+encodeURIComponent(origin);
const headers = {
Authorization: `Bearer ${googleApiAccessToken}`,
};
fetch(api, { headers }).then((response)=>{
if(response.status!==200)
{
msg = "No access to "+origin+" in GSC";
let msg_interlude="";
if(response.status==401)
{
msg_interlude=' - Have you tried turning "Google OAuth" on and off again? ';
}
prio = 0;
response.clone().json().then((data)=>{
console.log(data);
//msg = msg+" ("+data.error.code+"). "+that.partialCodeLink(data.error.message);
msg = data.error.message+" ("+data.error.code+") "+msg_interlude+'<br><a href="'+that.getGlobals().rulesUrl+'" target="_blank">Settings</a>';
done(that.createResult(lable, msg, 'warning', what, prio));
return null;
}).catch((err)=>{
});
}
response.json().then((data)=>{
prio = 500;
msg = "You have GSC access to "+data.siteUrl+" as \""+data.permissionLevel+"\".";
done(that.createResult(lable, msg, type, what, prio))
return null;
}).catch((err)=>{
});
}).catch((err)=>{
});
}