-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgoogle-indexing-api.go
49 lines (38 loc) · 994 Bytes
/
google-indexing-api.go
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
package main
import (
"context"
"flag"
"fmt"
"google.golang.org/api/indexing/v3"
"google.golang.org/api/option"
"os"
"strings"
)
func main() {
var urlsPath, credentials string
flag.StringVar(&urlsPath, "urls", "./urls", "path to file with links to pages")
flag.StringVar(&credentials, "credentials", "./service_account.json", "path to file with credentials downloaded from https://console.developers.google.com/iam-admin/serviceaccounts")
flag.Parse()
ctx := context.Background()
client, err := indexing.NewService(ctx, option.WithCredentialsFile(credentials))
if err != nil {
fmt.Println(err)
}
b, err := os.ReadFile(urlsPath)
if err != nil {
fmt.Println(err)
}
str := string(b)
urls := strings.Split(str, "\n")
for _, url := range urls {
notification := indexing.UrlNotification{
Type: "URL_UPDATED",
Url: url,
}
res, err := client.UrlNotifications.Publish(¬ification).Do()
if err != nil {
fmt.Println(err)
}
fmt.Println(res)
}
}