Skip to content

ceresti/go-vimeo

 
 

Repository files navigation

Build Status GoDoc codecov Go Report Card

go-vimeo

go-vimeo is a Go client library for accessing the Vimeo API.

Basic usage

import "github.com/silentsokolov/go-vimeo"


func main() {
    client := vimeo.NewClient(nil)

    // Specific optional parameters
	opt := &vimeo.ListCategoryOptions{
		ListOptions: vimeo.ListOptions{Page: 1, PerPage: 2},
	}

	cats, _, err := client.Categories.List(opt)
}

Authentication

The go-vimeo library does not directly handle authentication. Instead, when creating a new client, pass an http.Client that can handle authentication for you, for example the oauth2.

import (
	"golang.org/x/oauth2"
	"github.com/silentsokolov/go-vimeo"
)

func main() {
    ts := oauth2.StaticTokenSource(
        &oauth2.Token{AccessToken: "... your access token ..."},
    )
    tc := oauth2.NewClient(oauth2.NoContext, ts)

    client := vimeo.NewClient(tc)

    cats, _, err := client.Categories.List(nil)
}

Pagination

func main() {
    client := ...

    // Specific optional parameters
	opt := &vimeo.ListCategoryOptions{
		ListOptions: vimeo.ListOptions{Page: 2, PerPage: 2},
	}

	// Any "List" request
	_, resp, _ := client.Categories.List(opt)

	fmt.Printf("Current page: %d\n", resp.Page)
	fmt.Printf("Next page: %s\n", resp.NextPage)
	fmt.Printf("Prev page: %s\n", resp.PrevPage)
	fmt.Printf("Total pages: %d\n", resp.TotalPages)
}

Created/Updated request

func main() {
    client := ...

    // Specific request instance
    req := &vimeo.ChannelRequest{
        Name:        "My Channel",
        Description: "Awesome",
        Privacy:     "anybody",
    }

    ch, _, _ := client.Channels.Create(req)

    fmt.Println(ch)
}

Where "Me" service?

The "Me" service repeats the "Users" service, passing the empty string will authenticated user.

func main() {
    client := ...

    // Call /me API method.
    // Return current authenticated user.
    me, _, _ := client.Users.Get("")

    fmt.Println(me)
}

Upload video

import (
	"os"

	"golang.org/x/oauth2"
	"github.com/silentsokolov/go-vimeo"
)

func main() {
    client := ...
    filePath := "/Users/user/Videos/Awesome.mp4"

    f, _ := os.Open(filePath)

    video, resp, _ := client.Users.UploadVideo("", f)

    fmt.Println(video, resp)
}

Packages

No packages published

Languages

  • Go 100.0%