Coding Community

How to use the Livecoding.tv API using PHP

Livcecoding.tv API enables you to embed your stream on your site and use various resources.

In this article, we will use the Laravel framework and LiveCoding auth library hosted at https://github.com/LiveCodingTVOfficial/livecoding-auth

PREPARE

To start using API, you need to 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:

We need credentials data

  1. Client ID
  2. Client secret
  3. Redirect URL
  4. Scopes.

Client id and Client Secret are generated after app registration while Scopes as defined in LiveCoding API Documentation as follows.

Scopes

  • “read”: Read basic public profile information
  • “read:viewer”: Play live streams and videos for you
  • “read:user”: Read your personal information
  • “read:channel”: Read private channel information
  • “chat”: Access chat on your behalf

To use multiple scopes use like ‘read:user read:viewer read:channel chat’. The multiple scopes are used to grant multiple permissions to the app by user to access their profile information like in the picture below.

Next, we can build things up to be used to authorize the app.

Further, we can proceed to check authorization status

Here in if condition we check for authorization status –

$this->LivecodingAuth->getIsAuthorized(), if it’s not authorized then we can proceed to generate the authentication link using – $this->LivecodingAuth->getAuthLink().

$this->LivecodingAuth->getAuthLink() generates authorization link like 

After successful authorization Livecoding.tv redirects to our redirect URL

Now if $this->LivecodingAuth->getIsAuthorized() return true then else condition execute where we can perform our API calls.

API calls

After the successful authorization, we can perform API calls to endpoints mentioned here –

https://www.livecoding.tv/developer/documentation/#!/api

API call can be performed to end points using $this->LivecodingAuth->fetchData(‘<api_end_point>’)

Example

A sample API call to an endpoint can be like $this->LivecodingAuth->fetchData(‘user/’) to get loggedin user data similarly $this->LivecodingAuth->fetchData(‘videos/’) will return a json array consisting of all the videos from LiveCoding.tv.

Each API call returns JSON array of information. A sample API call returns following JSON array.

Auth Tokens

To save the auth tokens two type of storage is used session and text or file. To access tokens following variables can be used

  1. Access Token: $_SESSION[‘access_token’] or file_get_contents(‘access_token’)
  2. Refresh Token: $_SESSION[‘refresh_token’] or file_get_contents(‘refresh_token’)
  3. Expires In: $_SESSION[‘expires_in’] or file_get_contents(‘expires_in’)

These are all handled by the library by itself.

API Documentation

LiveCoding API Documentation can be accessed here.

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.
Related posts
Career DevelopmentCoding Community

AWS CodeCommit - An Alternative Version Control to GitHub

Career DevelopmentCoding Community

AWS Codestar - A great way to launch and deploy your Project using only AWS Tools

Coding Community

How Whelan Became a Vue.JS Expert through Hands-on Projects on Education Ecosystem during the Pandemic

Career DevelopmentCybersecurity

Top 12 Free Projects to Become a Cybersecurity Expert in 2020