List Contributions
This page describes how to list contributions.
Sample
The following sample shows how to list contributions from an user or organization with no filters applied.
Replace [USER-OR-ORGANIZATION]
with the resource name of the user or organization that the albums belong to, e.g. users/123
or organizations/123
.
tip
Tip: do not forget to replace CLIENT-ID
and CLIENT-SECRET
with valid IAM Service Account client credentials.
- Golang
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())
}
}