Please log in
 

Call webservices

This article will familiarise you with the basic skills needed to complete transactions on the KIT digital video platform. The usual process is to make a call to a webservice with a variety of parameters and receive an answer composed of data and media.

The API is based on a token transaction system. You can find documentation about this at Webservices API.

The transaction token (appToken) is available by calling a specific webservice with a specific parameter known as the application key (appKey). You cannot use KIT digital video API without this appToken. Please note that an appToken lasts for a period of 24h after it is generated, you don't have to generate it before each API call. The result of this is better performance. Also note that the appToken is the only mandatory parameter for each API call.


# 1 Transactions with PhP

There are several ways to call webservices with PhP. For this we recommend using cUrL.

Check to following links for more information about installing and using cUrl :

Follow the example below for instructions on how to use cUrl to get an appToken from your appKey.


// Parameter sent: your appKey. 
// The following key is a specimen only for an example purpose.
$tokenDatas[ 'appKey' ] = 'c1a79b135493b78aad0ad6b804cebaba';

// cUrl init
$call = curl_init( 'http://api.kewego.com/app/getToken/' );
curl_setopt($call, CURLOPT_HEADER, false);
curl_setopt($call, CURLOPT_RETURNTRANSFER, true);
curl_setopt($call, CURLOPT_POST, true);
curl_setopt($call, CURLOPT_HTTPHEADER, array('Expect:'));
curl_setopt($call, CURLOPT_TIMEOUT, 100);
curl_setopt($call, CURLOPT_POSTFIELDS, $tokenDatas);

// using cUrl to call the method
$response = curl_exec($call);
curl_close($call);

// processing
$obj = simplexml_load_string( $response );
$appToken = (string)$obj->message->appToken;
echo( $appToken );


# 2 Transactions with ActionScript3

Communication with KIT digital video platform is extremely simple with AS3. Actionscript has built-in classes allowing easy webservice management with XML.

Check to following links for more information about using these classes:

Follow the example below for instructions on how to use AS3 to generate an appToken from your appKey.


// Parameter sent: your appKey
// The following key is a specimen only for an example purpose
var appkey:String = "131fc831226678c6c86f2d8f1d693768"

// Init AS3 objects to perform transaction
var loader:URLLoader = new URLLoader()
loader.addEventListener( Event.COMPLETE , completeSessionHandler )
var token_request:URLRequest = new URLRequest( "http://api.kewego.com/app/getToken/" )
var token_variable:URLVariables = new URLVariables()

// Adding appKey to the call
token_variable.appKey = appkey
token_request.data = token_variable
 
// Defining the funtion that will recieve result from the call
// Result is XML
function completeSessionHandler( e:Event ):void
{
	var result:XML = new XML( loader.data )
	apptoken = result..appToken
	trace( "The session key used while 24h is : \n-> " + apptoken )
}

// Make the 
loader.load( token_request )


# 3 appKey and appToken

It is important to understand that appKey is a data-sensitive product permanently linked to your KIT digital product.

The example above, using AS3, is not advisable and is only given for you to understand more how to use webservice classes with AS3. Since the appKey is written directly into the code it can be retrieved easily.

The issue is the same with JavaScript and with all code executing on the client side: with a http traffic software like Charles Proxy or ServiceCapture, you can easily acquire the appKey when calling KIT digital API.

Note. appToken generation MUST be done server side. We strongly advise you to read the dedicated article for best practices.

  comments
No comments
Add comment