Skip to main content

Create an album

This page describes how to programmatically create a new album. There is currently no way to create an album idempotently, so be aware that for each call a new album will be created.

Sample

The following sample shows how to create an album with the specified display name.

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.

package main

import (
"context"
"log"

"golang.org/x/oauth2/clientcredentials"

"google.golang.org/api/option"

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

var (
AlbumParent = "[USER-OR-ORGANIZATION]"
AlbumDisplayName = "[DISPLAY-NAME]"

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

var (
TokenURL = "https://accounts.animeshon.com/o/oauth2/token"
Endpoint = "image.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 := &image.CreateAlbumRequest{
Parent: AlbumParent,
Album: &image.Album{
DisplayName: AlbumDisplayName,
},
}

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

log.Printf("name : %s", album.GetName())
log.Printf("display name: %s", album.GetDisplayName())
}
View on GitHub