/
main.go
64 lines (50 loc) · 1.47 KB
/
main.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"context"
"log"
"golang.org/x/oauth2/clientcredentials"
"google.golang.org/api/option"
gapic "github.com/animeapis/api-go-client/knowledge/v1alpha1"
knowledge "github.com/animeapis/go-genproto/knowledge/v1alpha1"
)
var (
ContributionName = "[CONTRIBUTION-NAME]"
ClientID = "[CLIENT-ID]"
ClientSecret = "[CLIENT-SECRET]"
)
var (
TokenURL = "https://accounts.animeshon.com/o/oauth2/token"
Endpoint = "knowledge.animeapis.com:443"
)
func main() {
ctx := context.Background()
config := &clientcredentials.Config{
ClientID: ClientID,
ClientSecret: ClientSecret,
TokenURL: TokenURL,
}
options := []option.ClientOption{
option.WithEndpoint(Endpoint),
option.WithTokenSource(config.TokenSource(ctx)),
}
client, err := gapic.NewClient(ctx, options...)
if err != nil {
log.Fatalf("NewClient: %s", err)
}
request := &knowledge.GetContributionChangesRequest{
Name: ContributionName,
}
changes, err := client.GetContributionChanges(ctx, request)
if nil != err {
log.Fatalf("GetContributionChanges: %s", err)
}
log.Println("---------------------------------------------------------")
for i, addition := range changes.Additions {
anime := addition.Entity.(*knowledge.EntryEntity_Anime).Anime
log.Printf("add[%d] name : %s", i, anime.GetName())
}
for i, deletion := range changes.Deletions {
anime := deletion.Entity.(*knowledge.EntryEntity_Anime).Anime
log.Printf("del[%d] name : %s", i, anime.GetName())
}
}