Skip to main content

Import trackers from third-parties

This page describes how to import trackers from third-parties.

Prerequisites

Trackers can be seamlessly imported from third-parties into Animeshon but the associated credentials must be configured beforehand through the Credentials API.

Sample

The following sample shows how to import trackers from third-parties.

Replace [USER-OR-AUDIENCE] with the resource name of the user or audience the trackers will be imported to, e.g. users/123 or audiences/123.

tip

Tip: do not forget to replace CLIENT-ID and CLIENT-SECRET with valid IAM Service Account client credentials.

package main

import (
"context"
"log"

"golang.org/x/oauth2/clientcredentials"

"google.golang.org/api/option"

gapic "github.com/animeapis/api-go-client/tracker/v1alpha1"
tracker "github.com/animeapis/go-genproto/tracker/v1alpha1"
)

var (
TrackerParent = "[TRACKER]"

Provider = tracker.Provider_MYANIMELIST

ClientID = "[CLIENT-ID]"
ClientSecret = "[CLIENT-SECRET]"
)

var (
TokenURL = "https://accounts.animeshon.com/o/oauth2/token"
Endpoint = "tracker.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 := &tracker.ImportTrackersRequest{
Parent: TrackerParent,
Provider: Provider,
}

response, err := client.ImportTrackers(ctx, request)
if err != nil {
log.Fatalf("ImportTrackers: %s", err)
}

log.Printf("waiting for import to be completed...")
if _, err := response.Wait(ctx); err != nil {
log.Fatalf("Wait: %s", err)
}

log.Printf("import successfully completed")
}
View on GitHub