• Stars
    star
    122
  • Rank 282,215 (Top 6 %)
  • Language
    Kotlin
  • License
    MIT License
  • Created over 8 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The Vimeo Java (Android) SDK

vimeo-networking

vimeo-networking is a JVM (Java & Kotlin) SDK used for interacting with the Vimeo API. The example app provided in this project shows the implementation in the context of an Android app.

WARNING: Please upgrade to version 3.x of this library by 3 March 2023 or manually disable certificate pinning on version 1.x or 2.x by this date. API requests that use certificate pinning will fail beginning on this date as the certificate that 1.x and 2.x pin to will expire and be replaced.

Branch Build Status
develop release workflow
Latest Version
JitPack

Contents

Prerequisites

In order to get started with using this library, there are a few prerequisites you need to satisfy, namely, creating a Vimeo account and registering an app with the API.

API Registration

In order to use this library and the Vimeo API, you will need an application registered with the Vimeo API. If you do not already have an application registered, you can do so here. If you do not have a Vimeo account, you will be prompted to sign up before registration.

After you have an application registered, you will have access to a few critical pieces of information required for initialization - the client identifier and client secret. These will both be located in the Authentication tab once you select your app from the list here.

More information about this and other API questions can be found on the API homepage.

Getting Started

For a more in depth look at the usage, refer to the example Android app. The example project includes implementations of client credential authentication, oauth authentication, and making simple requests.

Gradle

Make sure you include JitPack as a maven repository in your build.gradle file.

repositories {
  maven { url 'https://jitpack.io' }
}

Then add the following two dependencies to your build.gradle file.

implementation "com.github.vimeo.vimeo-networking-java:vimeo-networking:LATEST-VERSION"
implementation "com.github.vimeo.vimeo-networking-java:models:LATEST-VERSION"

See the CHANGELOG for the changes to each release.

Artifacts

There are several available artifacts for this SDK.

The core artifacts are

  • api-core - Contains general utilities, such as VimeoCallback.
  • auth - Contains the Authenticator and other authentication code.
  • request - Contains the VimeoApiClient and all request code.
  • models - Contains all the data transfer objects (DTOs) that are returned by the API.

One aggregate artifact exists as a convenience that bundles api-core, auth, and request

  • vimeo-networking - Includes all necessary modules except models.

Two alternative models artifacts exist

  • models-parcelable - Provides models that implement the Android Parcelable interface.
  • models-serializable - Provides models that implement the Java Serializable interface.

In order to use the SDK, you must always specify both vimeo-networking and one of models, models-parcelable, or models-serializable. Note that each models artifact is exclusive and cannot be used with another. You can only use one at a time. If you don't need Parcelable or Serializable, it's recommended to just use the default models.

JitPack

Generally, we recommend to use the latest release or alpha version that you can find in the releases tab. However, if you prefer to point to a specific commit, you can use JitPack to specify that commit:

implementation "com.github.vimeo.vimeo-networking-java:vimeo-networking:COMMIT_HASH"
implementation "com.github.vimeo.vimeo-networking-java:models:COMMIT_HASH"

Submodule

We recommend using JitPack, but if you'd like to use the library as a submodule, clone the repo:

git submodule add [email protected]:vimeo/vimeo-networking-java.git

Then in your build.gradle use:

implementation project(':vimeo-networking-java:vimeo-networking')
implementation project(':vimeo-networking-java:models')

Initialization

Access to the API is performed through the VimeoApiClient, which must be initialized prior to use. Consumers can choose to initialize a singleton instance or to create their own instance of the VimeoApiClient. In order to initialize the client, we need to construct an Authenticator, which is used to perform authentication requests and manage the SDK's authentication state. Like the VimeoApiClient, we can initialize a singleton instance or create a new instance of the Authenticator.

Initialization of the Authenticator is as follows:

// Create a new instance
val vimeoApiConfiguration = ...
val authenticator = Authenticator(vimeoApiConfiguration)

or

// Initialize the singleton
val vimeoApiConfiguration = ...
Authenticator.initialize(vimeoApiConfiguration)

Once we have the Authenticator initialized, we can proceed with initializing the VimeoApiClient as follows:

// Create a new instance
val vimeoApiConfiguration = ...
val authenticator = ...
val vimeoApiClient = VimeoApiClient(vimeoApiConfiguration, authenticator)

or

// Initialize the singleton
val vimeoApiConfiguration = ...
VimeoApiClient.initialize(vimeoApiConfiguration, Authenticator.instance())

The VimeoApiConfiguration is a customizable configuration that we use to provide the client identifier, client secret, and access scopes the SDK will use to communicate with the API. Constructing the VimeoApiConfiguration is done using the VimeoApiConfiguration.Builder that provides defaults for the other required configuration parameters.

In the below sections, we cover examples of ways to customize the VimeoApiClient instance. A full implementation can be found in the example app.

Configuration Tips for All Apps

We recommend the following for all apps when configuring the SDK with the VimeoApiConfiguration.Builder:

  • Provide a user agent to identify your app and the device using withUserAgent(String). By default the library creates its own user agent, but supplementing it with more info provides the Vimeo API with a better picture of what devices are accessing it. Not required, and we provide a default if none is provided.
  • Provide a cache directory with withCacheDirectory(File). By default the SDK does not set the cache directory and responses will not be cached, so you'll have to choose one to get the best performance.
  • Provide an AccountStore using withAccountStore(AccountStore). Unless you are accessing the API with a fixed access token, then you should probably provide a store that is disk backed. The default used by the SDK is an in-memory store that will not remember the logged in account after the app is restarted.

Configuration for Apps with Account Management

Create a VimeoApiConfiguration.Builder with your client identifier, client secret, and scope choices. After applying the above configuration tips, the configuration will be ready to use to initialize the Authenticator and VimeoApiClient.

And once initialization is complete, authenticate if necessary. This authentication can include client credentials or authentication via code grant.

Once authentication is complete, you can access the persisted VimeoAccount object through Authenticator.currentAccount.

Configuration Builder for Apps with Only One Developer Account

You can skip the need for client credentials or code grant requests if you provide an access token up front. With this access token you'll be able to make any requests that the access token's scope allows. You will NOT be able to switch accounts if you only supply the access token. To do that, refer to the above section.

You can generate an access token in the Authentication tab once you select your app from the list here.

Once you have the access token, you can easily initialize your Authenticator and VimeoApiClient with the below configuration..

val accessToken: String = ... // Generate your access token on the API developer website
val vimeoApiConfiguration = VimeoApiConfiguration.Builder(accessToken)
  .build()

After providing the access token, if you'd like to have access to the associated User object you'll need to make a call to VimeoApiClient.fetchCurrentUser(...).

Note: You will not be able to log out of the account associated with the access token provided to the VimeoApiConfiguration.Builder or use any other authentication methods in the Authenticator. This is because we don't want anyone to accidentally invalidate/delete the token which is being used to authenticate users in a production application. You will still be able to delete the token via the web developer console.

Authentication

Note: This section does not apply if you configured the SDK with a pre-generated access token instead of client credentials.

All calls to the Vimeo API must be authenticated. This means that before making requests to the API you must authenticate and obtain an access token. Two authentication methods are provided:

  1. Client credentials grant: This mechanism allows your application to access publicly accessible content on Vimeo.

  2. OAuth authorization code grant: This mechanism allows a Vimeo user to grant permission to your app so that it can access private, user-specific content on their behalf.

Client Credentials Grant

val vimeoApiConfiguration: VimeoApiConfiguration = ...
val authenticator: Authenticator = Authenticator(vimeoApiConfiguration)
val vimeoApiClient: VimeoApiClient = VimeoApiClient(vimeoApiConfiguration, authenticator)

authenticator.authenticateWithClientCredentials(
  vimeoCallback(
    onSuccess = {
      // Can do something with the VimeoAccount, or ignore.
      // It will be automatically stored in the AccountStore.
      // The VimeoApiClient is now ready to make requests.
    },
    onError = {
      // Handle the error.
    }
  )
)

OAuth Authorization Code Grant

  1. Set up a redirect URL scheme. Choose a redirect URL for the Vimeo website to redirect to after the user logs in. For example, you could use something like https://example.com/redirect, where example.com is your domain. The default URL is vimeo://auth.

    The URL you use must be registered at https://developer.vimeo.com/apps. After that, you need to configure the SDK to use your URL by using the withCodeGrantRedirectUrl(String) function on the VimeoApiConfiguration.Builder.

  2. Open the authorization URL in the web browser:

// Create the URI to log in with some request code you can verify.
val loginUri = createCodeGrantAuthorizationUri(requestCode = "1234567")

// Open the URI in a browser (Android shown here).
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(loginUri))
startActivity(intent)
  1. The web browser will open and the user will be presented with a webpage asking them to grant access based on the scope that you specified in your VimeoApiClientConfiguration above.

  2. Add an intent filter to your activity in the AndroidManifest to listen for the deeplink.

<intent-filter>
  <action android:name="android.intent.action.VIEW"/>
  <category android:name="android.intent.category.DEFAULT"/>
  <category android:name="android.intent.category.BROWSABLE"/>
  <!-- vimeo -->
  <data android:scheme="vimeo"/>
  <!-- auth -->
  <data android:host="auth"/>
</intent-filter>
  1. Then call Authenticator.authenticateWithCodeGrant(String, VimeoCallback) passing in the URL retrieved from val url = intent.data.toString() which will be supplied from the intent filter.

Note: You can find an example of both strategies in MainActivity.kt of the example app. You can also find more information on authentication in the authentication README or in the class documentation for Authenticator.

Requests

With the SDK configured and authenticated, you’re ready to start making requests to the Vimeo API.

Request Structure

Format

All requests functions are available on the VimeoApiClient and generally have the following common parameters:

  • uri: Used to specify which endpoint should be hit, required.
  • fieldFilter: An optional comma delimited list of the fields that you need from the API. See the API documentation on this for more information. While passing null is acceptable, limiting the data to what you need is strongly encouraged as it will reduce the response times.
  • queryParams: An optional map of key-value pairs that can be added to the query and further filter the response. See the API documentation on common parameters for more information.
  • cacheControl: The optional control that allows you to bypass the default caching behavior if you need to force a refresh or otherwise choose some different caching behavior for a specific request. Generally, leaving this null or providing CacheControl.FORCE_NETWORK are the only options we recommend using.
  • callback: The callback that will be invoked when the API response is received. It calls back on the callback thread provided by retrofit. For Kotlin consumers, a convenience function vimeoCallback can be used to construct an instance of the VimeoCallback class in a more idiomatic manner. For Java consumers, you'll have to rely on creating an instance of the VimeoCallback directly.

Requests start as soon as the function is invoked. All request functions return a VimeoRequest that can be used to cancel an in-flight request.

Validation

Most parameter validation is handled by retrofit and should be pretty lenient. For the uri parameter you will see in a lot request functions, the validation is slightly more strict. The uri cannot be empty, cannot be blank, and cannot contain a path traversal ... Otherwise the Vimeo API will validate your parameters and request.

Example Requests

Staff Picks

The below request will fetch the staff picks list.

val vimeoApiClient: VimeoApiClient = ...

vimeoApiClient.fetchVideoList(
  uri = STAFF_PICKS_VIDEO_URI,
  fieldFilter = null,
  queryParams = null,
  cacheControl = null,
  callback = vimeoCallback(
    onSuccess = {
      val videoList = it.data
      println("Staff Picks Success!")
    },
    onError = {
      println("Staff Picks Failure: ${it.message}")
    }
  )
)

Currently Authenticated User

val vimeoApiClient: VimeoApiClient = ...

vimeoApiClient.fetchCurrentUser(
  fieldFilter = null,
  cacheControl = null,
  callback = vimeoCallback(
    onSuccess = {
      // Update the UI with information about the current user
    },
    onError = {
      // Log the error and update the UI to tell the user there was an error
    }
  )
)

FAQs

How do I get a video that I own?

You can either request a Video object on its own or request a list of videos (VideoList).

Requesting a single video

To request a single video, you will need to know its URI. For this reason, requesting a single video is most helpful when you already have a copy of it and just need to refresh your local copy with the copy that exists on the Vimeo servers.

val uri = ...  // the video uri
val vimeoApiClient = ...

vimeoApiClient.fetchVideo(
  uri = uri,
  fieldFilter = null,
  queryParams = null,
  cacheControl = null,
  callback = vimeoCallback(
    onSuccess = {
      // Use the video.
    },
    onError = {
      // Voice the error.
    }
  )
) 

Requesting a list of videos

In order to get a list of your own videos you will need a URI from one of two ways:

As the authenticated user, just use the /me/videos endpoint:

val uri = "/me/videos" 

In the second approach, you must have a reference to your User object. You can get a list of videos a users owns as follows:

val user = ... // Get a reference to the User object
val uri = user.metadata?.connections?.videos?.uri

Then you can use the URI to get a list of videos

val uri = ... // Obtained using one of the above methods
val vimeoApiClient = ...

vimeoApiClient.fetchVideoList(
  uri = uri,
  fieldFilters = null,
  queryParams = null,
  cacheControl = null,
  callback = vimeoCallback(
    onSuccess = {
      // Getting the first video in the list.
      val firstVideo = it.data.data?.firstOrNull()
    },
    onError = {
      // Voice the error.
    }
  )
)

How do I play a video?

Once you have a Video object you have two choices - embed or play natively. All consumers of this library will be able to access the embed data. However, in order to play videos natively (for example, in a VideoView or using ExoPlayer on Android) you must have access to the VideoFile links, for which there are some restrictions (see the native playback section below).

Embed

All consumers of this library will have access to a video's embed HTML. Once you request a video you can get access to this as such:

val video = ... // Obtain a video as described in the requests section
val html: String? = video.embed?.html

// html is in the form "<iframe .... ></iframe>"
// display the html however you wish

Note: Android WebView is not officially supported by our embeddable player.

Native playback

The basic requirements for native playback are:

  1. User must be logged in.
  2. User must be the owner of the video.
  3. User must be PRO or higher (or the app must have the "can access owner's video files" capability).
  4. Token must have the ScopeType.VIDEO_FILES scope.
  5. User must be the owner of the API app making the request.

If you satisfy all of the requirements, you can choose to stream the videos in any manner you wish. You can get access to DASH or HLS video files through a video's Play representation.

val video = ... // Obtain a video you own as described above
val dashLink: String? = video.play?.dash?.link
val hlsLink: String? = video.play?.hls?.link

// Use one of the links to play

Found an Issue?

Please file it in the git issue tracker.

Want to Contribute?

If you'd like to contribute, please follow our guidelines found in CONTRIBUTING.md.

License

vimeo-networking-java is available under the MIT license. See the LICENSE file for more info.

Questions?

Tweet at us here: @VimeoEng.

Post on Stackoverflow with the tag vimeo-android.

Get in touch here.

Interested in working at Vimeo? We're hiring!

More Repositories

1

psalm

A static analysis tool for finding errors in PHP applications
PHP
5,440
star
2

player.js

Interact with and control an embedded Vimeo Player.
JavaScript
1,413
star
3

graph-explorer

A graphite dashboard powered by structured metrics
Python
1,060
star
4

php-mysql-engine

A MySQL engine written in pure PHP
PHP
544
star
5

player-api

Examples for our JavaScript and ActionScript player APIs.
450
star
6

vimeo.php

Official PHP library for the Vimeo API.
PHP
445
star
7

laravel

A Vimeo bridge for Laravel
PHP
384
star
8

stag-java

Speedy Type Adapter Generation
Java
351
star
9

VIMVideoPlayer

Deprecated: Please use [PlayerKit]( https://github.com/vimeo/PlayerKit) instead.
Objective-C
281
star
10

vimeo.js

Official Node.js library for the Vimeo API.
JavaScript
264
star
11

vimeo-oembed-examples

Some examples of how to use our oEmbed endpoint
HTML
237
star
12

vimeo.py

Official Python library for the Vimeo API.
Python
210
star
13

vimeo-unity-sdk

Easily stream your Vimeo videos into Unity or record and publish out to Vimeo.
C#
208
star
14

graphite-influxdb

An influxdb backend for Graphite-web and graphite-api
Python
198
star
15

vimeo-php-lib

Our official PHP library for the Advanced API.
PHP
180
star
16

tailgate

Tailgate is a nodejs app to pipe `tail -F` into websockets. It's a very simple way to have real-time access to your logs.
JavaScript
164
star
17

ABLincoln

A library for online experiments.
PHP
154
star
18

PlayerKit

Swift
154
star
19

py-money

Money class for Python 3
Python
121
star
20

vimeo-threejs-player

A plugin for streaming video from Vimeo to WebGL/VR/AR apps
JavaScript
88
star
21

tattletale.js

A utility to send console logs over XHR for server-side processing.
JavaScript
87
star
22

VimeoNetworking

The Vimeo API iOS SDK
Swift
83
star
23

vimeo-depth-player

A WebVR volumetric video renderer that uses color-depth based videos hosted on Vimeo.
JavaScript
83
star
24

aframe-vimeo-component

Stream Vimeo videos into WebVR.
JavaScript
81
star
25

simple-black-box

A simple black-box behavior testing framework
Shell
68
star
26

pentagon

Vault <-> Kubernetes Secrets
Go
59
star
27

VimeoUpload

The Vimeo iOS Upload SDK
Swift
59
star
28

whisper-to-influxdb

migrate (import) graphite data from whisper to influxdb
Go
58
star
29

smoketcp

Smokeping like tcp connectivity tester, reports to statsd. written in Golang
Go
58
star
30

VIMNetworking

The Vimeo iOS SDK
Objective-C
58
star
31

libvmod-boltsort

A fast Varnish module for sorting query string parameters.
C
58
star
32

vimeo-depth-viewer

OpenGL application for viewing depth and color video streams from Intel RealSense cameras
C++
52
star
33

iris

Vimeo Design System
TypeScript
50
star
34

carbon-tagger

native tag-based metrics for graphite/carbon
Go
50
star
35

go-util

Small reusable Go functions.
Go
44
star
36

Blueprint

aka How We Collaborate
41
star
37

graphite-api-influxdb-docker

docker image with graphite-api and graphite-influxdb
Shell
39
star
38

go-magic

Go Bindings for libmagic and an idiomatic API for getting a file's MIME type.
Go
39
star
39

rollup-plugin-bundle-size

A rollup plugin to show the size of the generated bundle(s).
JavaScript
29
star
40

vimeo-maxmsp

Play and manipulate Vimeo videos in Max/MSP and Jitter
Max
24
star
41

openapi

An OpenAPI specification for the Vimeo API.
17
star
42

VIMDeeplink

Simple Objc and Swift wrappers around the Vimeo iOS deeplink API
Swift
17
star
43

puppet-diamond

diamond module for puppet
Puppet
15
star
44

nagios-cloudwatch-plugin

AWS CloudWatch check Nagios plugin
Python
14
star
45

elevator

Validate and patch AV1 levels
Rust
12
star
46

puppet-statsd

statsd module for puppet
Puppet
11
star
47

VIMUpload

This library has been deprecated, use VimeoUpload instead
Objective-C
11
star
48

go-hammer

Go
10
star
49

VIMObjectMapper

An automatic JSON to model object converter
Objective-C
10
star
50

babel-plugin-transform-i18n

A Babel transform plugin to replace strings with their translations.
JavaScript
10
star
51

dials

Dials is an extensible configuration package for Go.
Go
9
star
52

go-clocks

A convenient package providing a Clock abstraction in Go
Go
9
star
53

go-taglog

Based on, and compatible with, the Go standard log package, but also provides additional functionality and features such as tagging.
Go
8
star
54

leaderelection

Go
8
star
55

ios-labs-staffpicks

An iOS Labs sample project
Swift
7
star
56

zendesk-ticket-history

JavaScript
7
star
57

grouplogger

Go
6
star
58

netstorage

go client for the new Akamai Netstorage http api
Go
6
star
59

caps

Go package to read/write popular video caption formats(mostly a port of pycaption)
Go
6
star
60

Uniform

Swift
6
star
61

alog

Another Go Logging Package
Go
5
star
62

vimeo-live-player-examples

Example application for using Vimeo Live M3U8 links with third-party players
HTML
5
star
63

graph-explorer-docker

Shell
5
star
64

eslint-config-player

ESLint config for all player team projects.
JavaScript
5
star
65

go-iccjpeg

A small utility package to extract ICC profiles from JPEGs.
Go
4
star
66

graphite-go

Go
4
star
67

go-retry

A small package for doing comprehensive retries.
Go
4
star
68

go-imgparse

A small go library to efficiently parse the resolution of various image format streams.
Go
4
star
69

vimeo-deeplink-android

A helper library to deep link into the official Vimeo Android App
Java
3
star
70

payment-gateway-logger

PHP
3
star
71

av1stats

An AV1 stream analysis CLI tool
Rust
3
star
72

omnipay-bluesnap

BlueSnap driver for the Omnipay PHP payment processing library
PHP
3
star
73

genepool

A golang package for building generic workpools in a standardized way
Go
2
star
74

omnipay-vindicia

Vindicia driver for the Omnipay PHP payment processing library
PHP
2
star
75

VimeoCommon

1
star
76

k8swatcher

Convenient watching interface for Kubernetes.
Go
1
star
77

policy

1
star