Introduction to Kaltura Client Libraries

Printer-friendly version
First Supported Kaltura Version: 

This document describes:

This document does not address how to implement specific flows using the Kaltura API.

Applicability

This document applies to Kaltura API version 3 and later.

Sample Code Usage

All sample code is PHP5, unless otherwise stated.

The sample code is designed to show you how to use the features of Kaltura client libraries.

The sample code is formatted for this document and includes hard-coded examples. Before using sample code copied from this document, replace the examples and adapt the formatting.

Document Conventions

  • File paths and names appear in bold.
    Example: /[INSTALLATION_PATH]/app/generator/config.ini
  • A string in brackets [] represents a value.
    Replace the string – including the brackets – with an actual value.
    Example: Replace [yourClientLibraryName] with Java.

Prerequisites

 To access the Kaltura API, you require:

  1. A Kaltura publisher account - To obtain a Kaltura account, start a free trialcontact us or Download Kaltura CE.
  2. Obtain your Kaltura API publisher credentials via the KMC Integration Settings.

Understanding Kaltura Client Libraries

What Is a Kaltura Client Library?

A Kaltura client library:

  • Is an SDK package in a specific programming language
  • Provides developers with easy access to the Kaltura API
  • Makes it easy to develop Kaltura applications

What Does a Kaltura Client Library Consist of?

A Kaltura client library is a collection of classes. Each class consists of objects and service classes. The collection of classes represents the entities, services, and actions that the Kaltura API provides.

When Do You Use a Kaltura Client Library?

Kaltura recommends that you use a Kaltura Client Library when you develop applications that interact with the Kaltura API.

What Are the Types of Client Libraries?

There are different types of client libraries:

  • Client libraries for the Kaltura Hosted Edition
  • Local client libraries for Kaltura On-Prem™ and Kaltura Community Edition (Kaltura CE)
  • Specialized Kaltura client libraries

To understand which type to use, see Deciding Where to Get a Client Library.

How Do You Start Using a Kaltura Client Library?

First, decide where to get a client library.

Then do one of the following:

When you have a client library:

Client Library Programming Languages

Kaltura provides downloadable client libraries for the Kaltura Hosted Edition in various programming languages. These languages also are available when generating a client library for Kaltura On-Prem and Kaltura CE. You can generate a client library for an additional language. See Generating a Client Library for a Language that Kaltura Does Not Provide.

Available Client Library Languages

  • PHP  
    • PHP5
    • Zend Framework-compatible library: Eases library integration in terms of coding standards and auto-loading
    • PHP4: For applications required to be compatible with PHP4
  • ActionScript 3       
  • Adobe Flex       
  • JavaScript       
  • C#       
  • Java       
  • Ruby       
  • Python
  • Objective-C/Cocoa

Where to Get a Client Library?

The type of client library that you use depends on your Kaltura edition and specific needs.

Kaltura Hosted Edition

If you use a standard Kaltura Hosted Edition, get a client library for the Kaltura Hosted Edition.

Kaltura On‑Prem

If you use a standard Kaltura On‑Prem, you need local client libraries. See Generating a Client Library for Kaltura On Prem and Kaltura CE.

Kaltura CE

If you use a standard Kaltura CE, you need local client libraries. See Generating a Client Library for Kaltura On Prem and Kaltura CE.

Generating a Client Library for a Language that Kaltura Does Not Provide

If you want a client library for a language that Kaltura does not provide, you need to generate a specialized Kaltura client library.

Kaltura welcomes contributions of client libraries for languages that Kaltura does not yet provide.

For more information, refer to Kaltura API Usage Guidelines.

Using APIs from a Customized Server Plugin

If you want a client library to include customized APIs from a server plugin, you need to generate a specialized Kaltura client library.

Using a Sub-Set of Kaltura APIs

If you want to use only a specific sub-set of Kaltura APIs without accessing other APIs, you need to generate a specialized Kaltura client library.

Getting a Client Library for Kaltura Hosted Edition

Who Uses Kaltura Hosted Client Libraries?

You need Kaltura Hosted client libraries if you use a standard Kaltura Hosted Edition.

If you use a different Kaltura edition, see Generating a Client Library for Kaltura On-Prem and Kaltura CE.

If you have specialized needs, see Generating a Specialized Kaltura Client Library.

How Is a Kaltura Hosted Client Library Generated?

Kaltura Hosted Edition client libraries are generated automatically based on the schema of the latest API version.

Client libraries are updated automatically when Kaltura updates Hosted servers with a new API version.

How to Get a Kaltura Hosted Client Library?

Download client libraries from Kaltura API SDK - Native Client Libraries.

Generating a Client Library for Kaltura On‑Prem and Kaltura CE

Who Generates Local Client Libraries?

You need to generate client libraries locally if you use standard Kaltura On-Prem or Kaltura CE.

If you use a standard Kaltura Hosted Edition, see Getting a Client Library for Kaltura Hosted Edition.

If you have specialized needs, see Generating a Specialized Kaltura Client Library.

Understanding Client Libraries and Self-Hosted Kaltura Servers

Kaltura On-Prem and Kaltura CE use self-hosted Kaltura servers.

Generating a client library locally ensures that the client library is compatible with the API version of the Kaltura edition on your self-hosted Kaltura server.

How Is a Kaltura Self-Hosted Client Library Generated?

If the version of your self-hosted edition is:

  • Dragonfly or earlier – Use the Kaltura server client generator to generate a client library locally.
  • Eagle or later – The Kaltura server client generator is executed automatically during installation.

Do not generate a client library locally when you use an application developed by Kaltura or the community that is packaged with a client library. Changing the client library in the application may cause the application to fail.

To generate a client library on your local Kaltura server:

(For Dragonfly and earlier versions of Kaltura self-hosted editions only:) Run the following script with root permissions:

cd /[INSTALLATION_PATH]/app/generator/
./generate.sh

The generator may not have permission to create the Kaltura client library files if you run the script without root permissions.

Generating a Specialized Kaltura Client Library

Who Generates a Specialized Client Library?

You need to generate specialized client libraries if you want:

  • A client library for a language that Kaltura does not provide
  • A client library to include customized APIs from a server plugin
  • To use only a specific sub-set of Kaltura APIs without accessing other APIs

If you use a standard Kaltura Hosted Edition, see Getting a Client Library for Kaltura Hosted Edition.

If you use a standard Kaltura On-Prem or Kaltura CE, see Generating a Client Library for Kaltura On-Prem and CE.

Generating a Specialized Client Library – Overview

Generating a specialized client library may require:

  • Creating a language-specific KalturaClientBase class
  • Creating a language-specific generator class
  • Including a Kaltura server plugin in a generator
  • Modifying a generator config.ini file
  • Running a generator

The required steps depend on the purpose of your specialized client library.

Required Steps for Specialized Client Libraries

A New Language

Including Server Plugin APIs

API Sub-Set

Creating a Language-Specific KalturaClientBase Class

Including a Kaltura Server Plugin in a Generator

Modifying a Generator config.ini File

Creating a Language-Specific Generator Class

Running a Generator

Running a Generator

Modifying a Generator config.ini File

 

 

Running a Generator

 

 

How to Generate a Specialized Client Library

Understanding the Client Library Generator

The Kaltura system includes generator code that generates client libraries.

The generator:

  • Is written in PHP
  • Uses the Zend_Reflection class
  • Parses the entire Kaltura API code, including the PHP code comments
  • Generates a client library according to the services and actions in the Kaltura API

Understanding the KalturaClientBase class

The KalturaClientBase class:

  • Contains all of the logic for communicating with the Kaltura API
  • Consists of methods for activities such as:
    • Submitting the HTTP request to the Kaltura API
    • Building the HTTP request from objects
    • Parsing the API output (from XML or other output format) back in to the response object,
    • Writing logs
  • Is independent of most Kaltura API services and actions
  • Is written manually for each client library

Understanding the Kaltura Client Library Generator Class

Each client library is generated using a language‑specific generator class.

The generator class has methods that are required to be implemented so that the code output is in the relevant language.

The generator class includes methods such as:

A generator's methods collectively generate the code of an entire language‑specific client library.

A generator class is written in PHP.

The generator class structure usually is the same for all languages.

The main difference between generator classes is the method outputs.

Required Developer Knowledge

A developer who writes a language‑specific generator requires:

  • Wide knowledge of the language of the generated client library
  • Familiarity with the language's limitations and behaviors.
    For example, whether the language supports nullable Boolean values.

Understanding Inclusion of a Kaltura Server Plugin in a Client Library

The Kaltura server supports extending the API with server plugins. Kaltura server plugins can provide new API services.

A server plugin usually contains a configuration file that includes the plugin in a client library.

A generator places all server plugin APIs in separate files.

The server can disable a server plugin. Similarly, a client library can exclude a server plugin by excluding the server plugin API files.

Coding Standard Compliance

When you write a Kaltura server plugin that extends the Kaltura API, Kaltura strongly recommends that you follow Kaltura API coding standards. A generator can handle server plugins for a client library accurately only if the plugin services comply with API coding standards, including code comments.

Understanding the Generator config.ini File

A generator refers to a config.ini file during execution.

The config.ini:

  • Specifies the client library package to generate
  • Specifies the services and actions to include or exclude
  • Is located in [INSTALLATION_PATH]/app/generator/config.ini

Producing a Specialized Kaltura Client Library

Creating a Language-Specific KalturaClientBase Class

To create a language-specific KalturaClientBase class:

  1. Download a client library for an existing language.
  2. Base the language-specific class on a KalturaClientBase class in the downloaded client library.
    KalturaClientBase is located in /[INSTALLATION_PATH]/app/generator/sources/[LANGUAGE_NAME]/

Creating a Language-Specific Generator Class

To create a custom language-specific generator class:

  1. Download a client library for an existing language.
  2. Base the language-specific class on a generator class in the downloaded client library.
    An example of a generator class path and name is: /[INSTALLATION_PATH]/app/generator/JavaClientGenerator.php

Including a Kaltura Server Plugin in a Generator

To include a Kaltura Server Plugin in a generator:

In your Kaltura server plugin, include a configuration that defines the plugin services included in client libraries.

The client library generator refers to the plugin configuration. The generator includes or excludes plugin services in the generated client libraries as specified in the plugin configuration.

Do not modify the generator config.ini file to include or exclude plugin services.

Modifying a Generator config.ini File

To include specific services and actions in the generator config.ini file:

  1. Open /[INSTALLATION_PATH]/app/generator/config.ini.
  2. For the language you are generating:
  • Add an include command with the services and actions to include. For example:

    include = batch.*, batchcontrol.*, jobs.*, media.addfrombulk

    An asterisk includes all of a service's actions. For example, batch.* includes all batch service actions.
    Specifying a service and action includes only the specific action of the service. For example, media.addfrombulk includes only the addfrombulk action of the media service.

  • If an include command exists, add to the command the services and actions you want to include.
  • Save the file.
  • To exclude specific services and actions from the generator config.ini file:

    1. Open /[INSTALLATION_PATH]/app/generator/config.ini.
    2. For the language you are generating:
    • Add an exclude command with the services and actions to exclude. For example:

      exclude = batch.*, batchcontrol.*, jobs.*, media.addfrombulk

      An asterisk excludes all of a service's actions. For example, batch.* excludes all batch service actions.
      Specifying a service and action excludes only the specific action of the service. For example, media.addfrombulk excludes only the addfrombulk action of the media service.

    • If an exclude command exists, add to the command the services and actions you want to exclude.
  • Save the file.
  • To include your client library in the generator config.ini file:

    1. Open /[INSTALLATION_PATH]/app/generator/config.ini.
    2. Add a section that specifies:
      1. The client library name
        For example, when generating a client library in a new language, typically you use the language name.
      2. The generator class name
    3. Save the file.

    Example of the section to add:

    [yourClientLibraryName]
    generator = [classNameOfYourGenerator]

    Running a Generator

    To generate a client library on your local Kaltura server:

    Run the following script with root permissions:

    cd /[INSTALLATION_PATH]/app/generator/
    ./generate.sh
    

    The generator may not have permission to create the Kaltura client library files if you run the script without root permissions.

    Your client library will be located under the output folder. For example: /[INSTALLATION_PATH]/web/content/clientslibs/[yourClientLibraryName]/

    Using a Kaltura Client Library

    Using a client library requires:

    1. Including a Client Library in an Application
    2. Instantiating a Client Object

    Using a client library may include:

    See Tips and Tricks for resources related to using a client library.

    For sample code in available client library languages, see Sample Code for Multiple Client Library Languages.

    Including a Client Library in an Application

    Before you can use a client library, you include the client library in your application.

    Depending on your programming language and application setup, either:

    • You explicitly include the client library in your application.
    • Your environment automatically includes the client library in your application using a feature such as the PHP auto-loading capability.

    The client library files included in your application depend on the client library generator. Usually you include only the KalturaClient file.

    The KalturaClient file is the main class that includes:

    • All other classes (including KalturaClientBase)
    • Most core Kaltura APIs:
      • Entity objects
      • Enumeration objects
      • Filter objects
      • Service classes
      • Service class methods

    To explicitly include a client library in your application:

    Implement the following code in your application:

    require_once ‘KalturaClient.php’;

    Excluding a Server Plugin from an Application

    All APIs that belong to a Kaltura server plugin are generated in separate files.

    The server can disable a server plugin. Similarly, a client library can exclude a server plugin by excluding the server plugin API files.

    To exclude a server plugin from an application:

    Do not include the server plugin API files in the client library.

    Instantiating a Client Object

    Before you can use a client library, you need a client object to perform actions with the Kaltura API.

    Depending on your use case, you may need to instantiate client objects multiple times.

    Instantiating a client object requires:

    1. Creating a configuration object
    2. Starting a Kaltura session
    3. Setting the Kaltura session for the configuration object

    Creating a Configuration Object

    To create a configuration object for a client library:

    Implement the following code:

    $kalturaConfig = new KalturaConfiguration(123);
    // where 123 is your partner ID
    
    $kalturaConfig->serviceUrl = ‘http://KalturaServerDomain’;
    // if you want to communicate with a Kaltura server which is 
    //    other than the default http://www.kaltura.com
    
    $kalturaClient = new KalturaClient($kalturaConfig);

    Starting a Kaltura Session

    You need to start a Kaltura session (KS) before using a client object for most API calls.

    For more information about a KS, refer to Kaltura API Usage Guidelines.

    To create a KS:

    Implement the following code:

    $ks = $kalturaClient->generateSession($adminSecret, $userId, KalturaSessionType::ADMIN, $partnerId, $expiry,$privileges);

    Setting the Kaltura Session for the Configuration Object

    To set the KS for the configuration object:

    Implement the following code:

    $kalturaClient->setKs($ks);

    Using a Client Object to Perform an API Call

    The Kaltura API structure consists of a list of services, represented by service objects. Each service object consists of different actions, represented by a method in the service object.

    For example:

    1. To call the media service to get a specific media entry instance from the Kaltura server entry, you use the get action.
      The result of media.get is an object of type KalturaMediaEntry.
    2. After performing the media.get call, you print the name of the entry.

    For more information about the Kaltura API structure, refer to Kaltura API Usage Guidelines.

    To perform a media.get call:

    Implement the following code:

    $entryId = ‘XXXYYYZZZA’;
    // a known ID of media entry that you have
    
    $mediaEntry = $client->media->get($entryId);

    To print the name of the media entry:

    Implement the following code:

    echo $mediaEntry->name;

    Example Workflow

    An example workflow for printing a known media item’s name from a client library involves:

    1. Including a Client Library in an Application
    2. Instantiating a Client Object
      1. Creating a configuration object
      2. Starting a Kaltura session
      3. Setting the Kaltura session for the configuration object
    3. Using a Client Object to Perform an API Call
      1. Performing a media.get call
      2. Printing the name of the media entry

    Sample Code for Printing a Known Media Item’s Name:

    require_once ‘KalturaClient.php’;
    
    $kalturaConfig = new KalturaConfiguration(123);
    // where 123 is your partner ID
    
    $kalturaConfig->serviceUrl = ‘http://KalturaServerDomain’;
    // if you want to communicate with a Kaltura server which is 
    //    other than the default http://www.kaltura.com
    
    $kalturaClient = new KalturaClient($kalturaConfig);
    
    $ks = $kalturaClient->generateSession($adminSecret, $userId, KalturaSessionType::ADMIN, $partnerId, $expiry,$privileges);
    $kalturaClient->setKs($ks);
    
    $entryId = ‘XXXYYYZZZA’;
    // a known ID of media entry that you have
    
    $mediaEntry = $client->media->get($entryId);
    
    echo $mediaEntry->name;

    Performing an API Call with a Server-Side Plugin Service

    Plugin APIs (services and objects) are generated in separate files. You can remove API files from the package easily without breaking inner dependency. See Excluding a Server Plugin from an Application.

    Since plugin APIs are not included in an application as a generic part of the client library, you use plugin APIs differently than client library objects.

    To perform a call using a plugin's metadata API:

    Implement the following code:

    require_once ‘KalturaClient.php’;
    
    $kalturaConfig = new KalturaConfiguration(123);
    // where 123 is your partner ID
    
    $kalturaConfig->serviceUrl = ‘http://KalturaServerDomain’;
    // if you want to communicate with a Kaltura server which is 
    //    other than the default http://www.kaltura.com
    
    $kalturaClient = new KalturaClient($kalturaConfig);
    
    $ks = $kalturaClient->generateSession($adminSecret, $userId, KalturaSessionType::ADMIN, $partnerId, $expiry,$privileges);
    $kalturaClient->setKs($ks);
    
    $entryId = ‘XXXYYYZZZA’;
    // a known ID of media entry that you have
    
    // instantiating a filter object required for the API call.
    $metadataFilter = new KalturaMetadataFilter();
    
    // 1111 is a known ID of metadata profile
    $metadataFilter->metadataProfileIdEqual = '1111';
    
    $metadataFilter->metadataObjectTypeEqual = KalturaMetadataObjectType::ENTRY;
    
    // filtering metadata objects for specific entry:
    $metadataFilter->objectIdEqual = $entryId;
    
    // instantiating a plugin object which holds its own services.
    // note that we pass the client to the plugin object
    $metadataPlugin = KalturaMetadataClientPlugin::get($kalturaClient);
    // calling the specific service ‘metadata’ and a specific action ‘list’
    $metadataForEntry = $metadataPlugin->metadata->listAction($metadataFilter);
    
    var_dump($metadataForEntry);

    Performing Multi-Requests

    The Kaltura API supports the multi-request feature.

    The multi-request feature allows you to stack multiple required calls and issue them in a single HTTP request. The multi-request feature reduces the number of network round trips between your server and Kaltura.

    You instruct the client to start a multi-request stack of calls. When all of the required calls are stacked, you instruct the client to perform the actual HTTP request.

    The multi-request feature supports the ability to have one request depend on the result of another request.

    For more information about the multi-request feature, refer to Kaltura API Usage Guidelines.

    To perform a multi-request:

    Implement code based on the following example:

    require_once ‘KalturaClient.php’;
    
    $kalturaConfig = new KalturaConfiguration(123);
    // where 123 is your partner ID
    
    $kalturaConfig->serviceUrl = ‘http://KalturaServerDomain’;
    // if you want to communicate with a Kaltura server which is 
    //    other than the default http://www.kaltura.com
    
    $kalturaClient = new KalturaClient($kalturaConfig);
    
    $ks = $kalturaClient->generateSession($adminSecret, $userId, KalturaSessionType::ADMIN, $partnerId, $expiry,$privileges);
    $kalturaClient->setKs($ks);
    
    $entryId = ‘XXXYYYZZZA’;
    // a known ID of media entry that you have
    
    try
    {
    	// tell the client to start stacking actions for multi-request
    	$kalturaClient->startMultiRequest();
    
    	// add first call to multi-request stack
    	$kalturaClient->media->get($entryId);
    
    	// create empty object for updating
    	$emptyEntryForUpdate = new KalturaMediaEntry();
    
    	// set dependency between second call and first call – 
    // the description to be set on the entry is the tags from the previous ‘media.get’ call
    	$emptyEntryForUpdate->description = '{1:result:tags}';
    
    	// add second call to multi-request stack
    	$kalturaClient->media->update($entryId, $emptyEntryForUpdate);
    
    	// tell the client to perform the actual HTTP request for the stacked actions
    	$results = $kalturaClient->doMultiRequest();
    
    	// extract result objects from array of results
    $mediaEntry = $results[0];
    $updatedMediaEntry = $results[1];
    
    echo "entry tags: " . $mediaEntry->tags;
    echo "new entry desription: " . $updatedMediaEntry->description;
    }
    catch(Exception $ex)
    {
    	echo “could not get entry from Kaltura. Reason: “ . $ex->getMessage();
    }

    Error Handling

    The Kaltura API can return errors.

    The API follows object-oriented programming (OOP) principles. A client library is generated as OOP code that consists of classes and methods. The best way for a client library to handle errors natively is by using exceptions, as follows:

    A client library parses an API output. If the API returned an error, the client throws an exception that includes the error code and message that the Kaltura server returned.

    Kaltura recommends that you wrap API calls in your code in a try-catch block to enable user-friendly error handling. This approach prevents your application from crashing.

    For more information about Kaltura API error handling, refer to Kaltura API Usage Guidelines.

    API Error Handling – Sample Code

    The following is an example of error handling for printing a known media item’s name:

    require_once ‘KalturaClient.php’;
    
    $kalturaConfig = new KalturaConfiguration(123);
    // where 123 is your partner ID
    
    $kalturaConfig->serviceUrl = ‘http://KalturaServerDomain’;
    // if you want to communicate with a Kaltura server which is 
    //    other than the default http://www.kaltura.com
    
    $kalturaClient = new KalturaClient($kalturaConfig);
    
    $ks = $kalturaClient->generateSession($adminSecret, $userId, KalturaSessionType::ADMIN, $partnerId, $expiry,$privileges);
    $kalturaClient->setKs($ks);
    
    $entryId = ‘XXXYYYZZZA’;
    // a known ID of media entry that you have
    
    try
    {
    $mediaEntry = $client->media->get($entryId);
    echo $mediaEntry->name;
    }
    catch(Exception $ex)
    {
    	echo “could not get entry from Kaltura. Reason: “ . $ex->getMessage();
    }

    Tips and Tricks

    Sample Code for Multiple Client Library Languages

    The sample code demonstrates the following scenario for using a Kaltura client library:

    1. Including a Client Library in an Application
    2. Instantiating a Client Object
      1. Creating a configuration object
      2. Starting a Kaltura session
      3. Setting the Kaltura session for the configuration object
    3. Using a Client Object to Perform an API Call (media.get)
      1. Performing a media.get call
      2. Printing the name of the media entry
    4. Error Handling

    To understand the sample code in detail, see Using a Kaltura Client Library.

    Sample Code – Available Languages

    Sample code appears for:

    PHP5

    require_once ‘KalturaClient.php’;
    
    $kalturaConfig = new KalturaConfiguration(123);
    // where 123 is your partner ID
    
    $kalturaConfig->serviceUrl = ‘http://KalturaServerDomain’;
    // if you want to communicate with a Kaltura server which is 
    //    other than the default http://www.kaltura.com
    
    $kalturaClient = new KalturaClient($kalturaConfig);
    
    $ks = $kalturaClient->generateSession($adminSecret, $userId, KalturaSessionType::ADMIN, $partnerId, $expiry,$privileges);
    $kalturaClient->setKs($ks);
    
    $entryId = ‘XXXYYYZZZA’;
    // a known ID of media entry that you have
    
    try
    {
    $mediaEntry = $client->media->get($entryId);
    echo $mediaEntry->name;
    }
    catch(Exception $ex)
    {
    	echo “could not get entry from Kaltura. Reason: “ . $ex->getMessage();
    }

    Java

    package com.kaltura.code.example;
    import com.kaltura.client.enums.*;
    import com.kaltura.client.types.*;
    import com.kaltura.client.services.*;
    import com.kaltura.client.KalturaApiException;
    import com.kaltura.client.KalturaClient;
    import com.kaltura.client.KalturaConfiguration;
    class CodeExample{
    public static void main(String[] args){
    	KalturaConfiguration config = new KalturaConfiguration();
    	config.setPartnerId(123);
    	// where 123 is your partner ID
    
    		config.setEndpoint("http://www.kaltura.com/");
    	// if you want to communicate with a Kaltura server which is 
    		//    other than the default http://www.kaltura.com
    
    		KalturaClient client = new KalturaClient(config);
    
    		String entryId = null;
    		int version = 0;
    
    		String ks = client.generateSession(
    				adminSecret, userId, type, partnerId, expiry, privileges
    		);
    
    		client.setSessionId(ks);
    	entryId = "XXXYYYZZZA";
    		// a known ID of media entry that you have
    
    	try{
    			KalturaMediaEntry mediaEntry = client.getMediaService().get(entryId);
    			System.out.print(mediaEntry.getName());
    		}catch(KalturaApiException e){
    			System.out.print(“could not get entry from Kaltura. Reason: “);
    			e.printStackTrace();
    		}
    }
    }

    C#

    using System.Collections.Generic;
    using System.Text;
    using System.IO;
    namespace Kaltura{
    	class CodeExample{
    		static void Main(string[] args){
    			KalturaConfiguration config = new KalturaConfiguration(123);
    			// where 123 is your partner ID
    
    			config.ServiceUrl = "http://www.kaltura.com/";
    			// if you want to communicate with a Kaltura server which is 
    			//    other than the default http://www.kaltura.com
    
    			KalturaClient client = new KalturaClient(config);
    			String ks = client.GenerateSession(
    				adminSecret, userId, type, partnerId, expiry, privileges
    			);
    			// GenerateSession method is already implemented in the C# library
    
    			String entryId = null;
    			int version = 0; 
    			client.KS = ks;
    
    			entryId = "XXXYYYZZZA";
    			// a known ID of media entry that you have
    
    			try
    			{
    				KalturaMediaEntry mediaEntry = client.MediaService.Get(entryId);
    				System.Console.WriteLine(mediaEntry.name);
    			}
    			catch(KalturaException ex)
    			{
    				System.Console.WriteLine(“could not get entry from Kaltura. “);
    				System.Console.WriteLine(“Reason: “);
    				System.Console.WriteLine(ex.toString());
    			}
    		}
    	}
    }

    Python

    from KalturaClient import *
    
    config = KalturaConfiguration(123)
    # where 123 is your partner ID
    
    config.serviceUrl = "http://devtests.kaltura.co.cc/"
    # if you want to communicate with a Kaltura server which is
    #    other than the default http://www.kaltura.com
    
    client = KalturaClient(config)
    
    ks = client.generateSession(adminSecret, userId, type, partnerId, expiry, privileges)
    
    client.setKs(ks)
    
    entryId = "XXXYYYZZZA";
    # a known ID of media entry that you have
    
    try:
        mediaEntry = client.media.get(entryId)
        print mediaEntry.getName()
    except KalturaException, e:
        print "could not get entry from Kaltura. Reason: %s" % repr(e)

    Ruby

    require "ruby_client.rb"
    
    include Kaltura
    
    config = KalturaConfiguration.new(123)
    # where 123 is your partner ID
    
    config.service_url = 'http://www.kaltura.com/'
    # if you want to communicate with a Kaltura server which is
    #    other than the default http://www.kaltura.com
    
    client = KalturaClient.new(config)
    
    ks = client.session_service.start (secret, userId, type, partnerId, expiry, privileges)
    client.ks = ks
    
    entry_id = 'XXXYYYZZZA'
    
    media_entry = client.media_service.get(entry_id)
    puts media_entry.name

    The Ruby client library does not include a local generateSession function to generate a Kaltura session. Instead, use the session service to start a session.

    AS3

    package com.kaltura.code.example
    {
    	import com.kaltura.KalturaClient;
    	import com.kaltura.commands.baseEntry.BaseEntryGet;
    	import com.kaltura.config.KalturaConfig;
    	import com.kaltura.events.KalturaEvent;
    	
    	
    	public class CodeExample {
    		private var _client:KalturaClient;
    		
    		public function CodeExample()
    		{
    			// create KalturaClient:
    			var configuration:KalturaConfig = new KalturaConfig();
    			configuration.partnerId = "123";	// where 123 is your partner ID
    			configuration.ignoreNull = 1;
    			configuration.ks = loaderInfo.parameters.ks; 	// ks passed in as flashvar 
    			
    			_client = new KalturaClient(configuration); 
    			
    			var entryId:String = "XXXYYYZZZA"; // a known ID of media entry that you have
    			var beg:BaseEntryGet = new BaseEntryGet(entryId);
    			beg.addEventListener(KalturaEvent.COMPLETE, handleEntryGet);
    			beg.addEventListener(KalturaEvent.FAILED, handleEntryGet);
    			_client.post(beg);
    		}
    		
    		private function handleEntryGet(e:KalturaEvent):void {
    			e.target.removeEventListener(KalturaEvent.COMPLETE, handleEntryGet);
    			e.target.removeEventListener(KalturaEvent.FAILED, handleEntryGet);
    			if (e.type == KalturaEvent.COMPLETE) {
    				trace(e.data.name);
    			}
    			else {
    				trace("could not get entry from Kaltura. Reason: ", e.error.errorMsg);
    			}
    		}
    	}
    }

    JavaScript

    <script type="text/javascript">
    	var kConfig;
    	var kClient;
    	var partnerId = 123; // where 123 is your partner ID
    	var userId = "someone";
    	var expiry = 86400;
    	var privileges = "";
    
    	// call server side to generate a KS for you so secrets will not be compromised
    	var ks = ajaxGetKs(partnerId, userId, expiry, privileges);
    
    	var entryId = "XXXYYYZZZA"; // a known ID of media entry that you have
    	
    	function pageLoad() {
    		kConfig = new KalturaConfiguration(partnerId);
    		kConfig.serviceUrl = "http://www.kaltura.com";
    		// if you want to communicate with a Kaltura server which is
    		//    other than the default http://www.kaltura.com
    
    		kClient = new KalturaClient(kConfig);
    		kClient.ks = ks;
    		getEntrySample();
    		return false; 
    	}
    
    	function getEntrySample() {
    		kClient.media.get(getEntryResult, entryId);
    	}
    
    	function getEntryResult(success, data) {
    		if (data.code) {
    			alert("Error: "+data.message);
    		} else {
    			alert("Your entry name: "+data.name);
    		}
    	}
    </script>

    Handling Secrets

    Since JavaScript is a client-side programming language, secrets included in the code are compromised. Exposing secrets causes a security issue.

    To avoid exposing the KS secret, Kaltura recommends calling an AJAX (or similar methodology) server‑side action that returns a KS. The sample code implements the recommendation:

    var ks = ajaxGetKs(partnerId, userId, expiry, privileges);

    For more information about security issues related to accessing the Kaltura API using client-side technology, refer to Kaltura API Usage Guidelines.

    Objective-C/Cocoa

    #import "KalturaClient.h"
    
    #define SERVICE_URL (@"http://www.kaltura.com")
    #define ADMIN_SECRET (@"1234abcd")
    #define PARTNER_ID (1234)
    #define USER_ID (@"user")
    #define ENTRY_ID (@"0_12345678")
    
    @interface GetEntrySample : NSObject
    
    - (void)sample;
    
    @end
    
    @implementation GetEntrySample
    
    - (void)sample
    {
        KalturaClientConfiguration* config = [[KalturaClientConfiguration alloc] init];
        config.serviceUrl = SERVICE_URL;
        KalturaNSLogger* logger = [[KalturaNSLogger alloc] init];
        config.logger = logger;
        [logger release];           // retained on config
        config.partnerId = PARTNER_ID;
        KalturaClient* client = [[KalturaClient alloc] initWithConfig:config];
        [config release];           // retained on the client
    
        client.ks = [KalturaClient generateSessionWithSecret:ADMIN_SECRET withUserId:USER_ID withType:[KalturaSessionType ADMIN] withPartnerId:PARTNER_ID withExpiry:86400 withPrivileges:@""];
    
        KalturaMediaEntry* mediaEntry = [client.media getWithEntryId:ENTRY_ID];
        if (client.error != nil)
            NSLog(@"Failed to get entry, domain=%@ code=%d", error.domain, error.code);
        else
            NSLog(@"Entry name %@", mediaEntry.name);
                                    
         [client release];
    }
    
    @end
    (64376 reads)