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
To start using API, you need to register an app on https://www.livecoding.tv/developer/applications/
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
Client id and Client Secret are generated after app registration while Scopes as defined in LiveCoding API Documentation as follows.
Scopes
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.
private $LivecodingAuth; public function __construct() { $client_id = '<client_id>'; $client_secret = '<client_Secret>'; $redirect_url = '<redirect_url>'; $scope = '<scopes>'; try { $this->LivecodingAuth = new LivecodingAuth($client_id, $client_secret, $redirect_url, $scope); } catch(Exception $ex) { die($ex->getMessage()); } }
Further, we can proceed to check authorization status
public function index() { if (!$this->LivecodingAuth->getIsAuthorized()) { $this->LivecodingAuth->getAuthLink(); } else { $this->LivecodingAuth->fetchData('<api_end_point>'); } }
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
'https://www.livecoding.tv/o/authorize/?scope=$scope&state=57d597c3b0703&redirect_uri=$redirect_uri&response_type=code&client_id=$client_id'.
After successful authorization Livecoding.tv redirects to our redirect URL
<redirect_url>/?state=57df5425a5c80&code=<authorization_code>
Now if $this->LivecodingAuth->getIsAuthorized() return true then else condition execute where we can perform our 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>’)
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.
[ { "Url": "https://www.livecoding.tv/api/videos/051115-intelligent-snes-disassembler-python/", "slug": "051115-intelligent-snes-disassembler-python", "user": "https://www.livecoding.tv/api/users/andreaorru/", "title": "051115 Intelligent SNES disassembler [Python]", "description": "I'm building an intelligent disassembler for Super Nintendo ROMs.\r\nIt follows the execution flow of the program and tries to discover all the code in the ROM.\r\n\r\nThe goal is to extract all the info useful to statically recompile the games to port them on other platforms (i.e. Nintendo DS).", "coding_category": "Python", "difficulty": "expert", "language": "English", "product_type": "other", "creation_time": "2015-11-06T04:17:59.196863Z", "duration": 4100, "region": "eu-london", "viewers_overall": 16, … }, ... ]
To save the auth tokens two type of storage is used session and text or file. To access tokens following variables can be used
These are all handled by the library by itself.
LiveCoding API Documentation can be accessed here.
Have any questions? Don’t forget to comment below and let us know.
We’re thrilled to announce an exciting opportunity for you to win not one but two…
Acquiring practical skills is crucial for career advancement and personal growth. Education Ecosystem stands out…
Artificial Intelligence (AI) has been making significant strides in various industries, and the software development…
Another week to bring you the top yield platforms for three of the most prominent…
If you hold a large volume of LEDU tokens above 1 million units and wish…
It’s another week and like always we have to explore the top yield platforms for…
View Comments
I hope the Golang one comes up too :)
Thanks for this. I'm a broadcaster at Livecoding.tv . This is really helpful.