Getting Access Tokens

 

In this section we explain how to get access authentication tokens and implement the API in your apps.

Getting a token

Authentication tokens is obtained from the JunctionTV OAuth API. Along with access tokens, it is required to obtain client credentials (a client id and a client password) they are specific to the API and operations that are required to be accessed or performed.

Once credentials are obtained, access authentication token by making a POST request to:

POST – https://cloud.junctiontv.net/ums/2.0/oauth/

Header

Content-Type

optional

application/x-www-form-urlencoded

Authorization

required

Basic {client_id}:{client_secret}

NOTE: {client_id}:{client_secret} string must be Base64-encoded.

The response of a successful authorization access call ( Status #200) will look as follows:-

The expired_in value is the number of seconds that the access token is valid for.

The response of a invalid authorization access call ( Status #401) will look as follows:-

The response of an ERROR in authorization access call ( Status #404) will look as follows:-

HTTP Status 404

Implementation Strategies

App will only be making periodic calls to the JTV APIs.
If the API call (i.e. HTTP response) is successful, with response Status code is 200, then continue with further process.
Else, if the response Status code is 401, that means unauthorized call. Follow the flow loop to get Authentication Token.
At last if the response Status code is not 401, that means invalid API call, continue the loop to make API calls.

The processing sequence will look like this:

AuthFinal

Code Samples

Here are some code samples to help you get started.

Python example

Python script attempts to make an Analytics API call, but if the call fails on an UNAUTHORIZED error, it fetches a new access token and retries the call.

Python code

PHP example

This is a simple proxy that takes client credentials and an API call, gets an access token, makes the API request, and returns the results to the client.

PHP code

JAVA example

This is a simple proxy that takes client credentials and an API call, gets an access token, makes the API request, and returns the results to the client.

JAVA code

ROKU example

This is a simple proxy that takes client credentials and an API call, gets an access token, makes the API request, and returns the results to the client.

Bright script code

The ApiAuthentication() can be called from your main script like this :-

For much better understating and curated scripts follow us at Github