Coding Community

How to use the Livecoding.tv API using Python

Livcecoding.tv API enables you to connect your application to Livecoding and its different resources.

In this article, we will use the Django framework and Requests library. The same method can be interpolated to other frameworks and library with ease.

Prepare

To prepare to use API, register an app on https://www.livecoding.tv/developer/applications/

Authorization

The first thing we have to do before using API methods is to authorize.

Authorization in livecoding.tv API works through standard oAuth protocol, so first we need to implement methods to get an access token with API credentials and later refresh them.

Assume that we have model object with credentials data:

All methods implemented in the Client class:

In auth() method, we make a post request to Livecoding.tv auth endpoint with an authorization code and then retrieve the access token and refresh token and save them for later use with API requests.

In order to authorise code from authorization server, we have to get request to authorization server:

After successful authorization Livecoding.tv redirects to our redirect URL, where we can handle authorization code, and continue the auth() procedure.

For convenient use lets create views for it:

 

Access token has expiration period, so we need periodically refresh it:

API calls

In order to call API methods we need to supply access token with special HTTP header:

“Authorization: Bearer mytoken”

Let implement method to form it:

And now all necessary is ready to retrieve data through API.

For example, we want to get scheduled broadcasts. So we have to make proxy method for API method “scheduledbroadcast”, and for convenient use, we will make the ability to pass any params to it.To avoid access token expiration, we will refresh it on every call.

And then use it like:

In that way, you can use any method supported by API
https://www.livecoding.tv/developer/documentation/

Have any questions? Don’t forget to comment below and let us know.

About author

About Author Dr. Michael Jurgen Garbade is the founder of LiveEdu.TV, Kyuda, Education Ecosystem. He is future Venture Capitalist, Future Politician and always on the lookout for the Next Big Challenge. Obtained Masters in business administration and physics, and a Ph.D. in finance with professional work experience in high-paced environments at Fortune 500 companies like Amazon and General Electric. Expertize: Python, PHP, Sencha Touch & C++, SEO, Finance, Strategy & E-commerce. He speaks English and German and has worked in the US, Europe, and Asia. At Education Ecosystem he is the CEO and runs business operations.