/
main.go
67 lines (52 loc) · 1.39 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
65
66
67
package main
import (
"context"
"errors"
"log"
"golang.org/x/oauth2/clientcredentials"
"google.golang.org/api/iterator"
"google.golang.org/api/option"
gapic "github.com/animeapis/api-go-client/knowledge/v1alpha1"
knowledge "github.com/animeapis/go-genproto/knowledge/v1alpha1"
)
var (
ContributionParent = "[USER-OR-ORGANIZATION]"
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.ListContributionsRequest{
Parent: ContributionParent,
}
it := client.ListContributions(ctx, request)
for {
contribution, err := it.Next()
if err != nil {
if errors.Is(err, iterator.Done) {
log.Println("---------------------------------------------------------")
return
}
log.Fatalf("ListContributions: %s", err)
}
log.Println("---------------------------------------------------------")
log.Printf("name : %s", contribution.GetName())
}
}