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.

Avatar
About author

I, Dr. Michael J. Garbade is the co-founder of the Education Ecosystem (aka LiveEdu), ex-Amazon, GE, Rebate Networks, Y-combinator. Python, Django, and DevOps Engineer. Serial Entrepreneur. Experienced in raising venture funding. I speak English and German as mother tongues. I have a Masters in Business Administration and Physics, and a Ph.D. in Venture Capital Financing. Currently, I am the Project Lead on the community project -Nationalcoronalvirus Hotline I write subject matter expert technical and business articles in leading blogs like Opensource.com, Dzone.com, Cybrary, Businessinsider, Entrepreneur.com, TechinAsia, Coindesk, and Cointelegraph. I am a frequent speaker and panelist at tech and blockchain conferences around the globe. I serve as a start-up mentor at Axel Springer Accelerator, NY Edtech Accelerator, Seedstars, and Learnlaunch Accelerator. I love hackathons and often serve as a technical judge on hackathon panels.