Kaltura API - POST (http://www.kaltura.com/api/startsession)

4 replies [Last post]
Joined: 07/15/2009
Points: 10

Are these HTTP POST/GET API's still being used? I am trying to use these API's to get XML data back. Here is my code:

function startSession () {

                //secret = "--secret code --";
                //adminsecret = "--secret admin code --";

                $ch = curl_init();
                $ksess = array();
                //$ksess['format'] = 2;
                //$ksess['partner_id'] = --oops--;
                //$ksess['subp_id'] = --oops--;
                //$ksess['uid'] = "--oops--";
                //$ksess['secret'] = "--secret code --";
                $ksess['secret'] = "--secret admin code --";
                $ksess['expiry'] = 86400;
                $ksess['admin'] = 1;
                $ksess['privileges'] = 1;
               

                curl_setopt($ch,CURLOPT_URL,'http://www.kaltura.com/api/startsession');
                //curl_setopt($ch,CURLOPT_POSTFIELDS,$ksess);
                curl_setopt($ch,CURLOPT_POSTFIELDS,'secret=--secret admin code --&expiry=86400&admin=1&privileges=1');
                //curl_setopt($ch,CURLOPT_HTTPHEADERS,'Content-Type: text/html');
                curl_setopt($ch,CURLOPT_HTTPHEADERS,'Content-Type: multipart/form-data');
                curl_setopt($ch,CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9) Gecko/2008052906 Firefox/3.0');
                curl_setopt($ch,CURLOPT_POST,1);
                curl_setopt($ch,CURLOPT_VERBOSE,1);
                curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
                curl_setopt($ch, CURLOPT_TIMEOUT, 4);
                curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
                $result = curl_exec($ch);
                //echo "result: " .$result. "<br/>";
               
                //echo "HTTP_RAW_POST_DATA: " .$HTTP_RAW_POST_DATA. "<br/>";

                if ( curl_errno($ch) ) {
print "error encountered\n";
                        $result = 'ERROR -> ' . curl_errno($ch) . ': ' . curl_error($ch);
                } else {
                        $returnCode = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);
                               
                        switch($returnCode){
                                case 200:
                                                break;
                                default:
                                                $result = 'HTTP ERROR -> ' . $returnCode;
                                                break;
                        }

                        //$keith = curl_getinfo($ch);
                        //var_dump($keith);
                }

                curl_close($ch);
                return $result;

}

$results = startSession();

echo "Results:\n" . $results;

In this code, i'm trying to start a session so I can get other information about one of my playlists. As you can see, I have tried it both ways using an array and just passing in a raw string POST data string. The secret var is my admin secret.
When I run this from a command line, I get the following:

* About to connect() to <a href="http://www.kaltura.com" title="www.kaltura.com">www.kaltura.com</a> port 80 (#0)
*   Trying 208.122.58.131... * connected
* Connected to <a href="http://www.kaltura.com" title="www.kaltura.com">www.kaltura.com</a> (208.122.58.131) port 80 (#0)
> POST /api/startsession HTTP/1.1
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9) Gecko/2008052906 Firefox/3.0
Host: <a href="http://www.kaltura.com
Accept:" title="www.kaltura.com
Accept:">www.kaltura.com
Accept:</a> */*
Content-Length: 73
Content-Type: application/x-www-form-urlencoded

* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Date: Tue, 21 Jul 2009 14:58:03 GMT
< Server: Apache/2.2.11 (Fedora)
< X-Powered-By: PHP/5.2.6
< Set-Cookie: kalt=8d174aiiqn1kalge5dnvptm3r2; path=/
< Expires: Thu, 19 Nov 1981 08:52:00 GMT
< Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
< Pragma: no-cache
< Vary: Accept-Encoding
< X-UA-Compatible: IE=EmulateIE7
< Content-Length: 460
< Connection: close
< Content-Type: text/xml; charset=utf-8
<
* Closing connection #0
string(460) "<?xml version="1.0" encoding="ISO-8859-1"?><xml><result><serverTime>1248188283</serverTime></result><error><num_0><code>UNKNOWN_PARTNER_ID</code><desc>Unknown partner_id []</desc></num_0></error><debug><sigtype>1</sigtype><validateSignature></validateSignature><signature>2eab4b56e10175f1b77656afcfc76c3c</signature><execute_impl_time>0</execute_impl_time><execute_time>0.0090339183807373</execute_time><total_time>0.0092461109161377</total_time></debug></xml>"

It's returning an error of "unknown partner ID".

Can someone tell me what i'm doing wrong, please?

Thanks,
Keith

Joined: 04/05/2009
Points: 354

Have you double checked that your partner details are correct? Can you log into the KMC fine?

Also, have you considered using the PHP client library?

http://www.kaltura.org/project/kcl_php

Joined: 07/15/2009
Points: 10

Hi Chris,
Yes, I have verified my partner details and I can log in just fine. That's how I got my partnerid info. I actually began with the kcl_php code as a base. I modded it with my info and to pull back info on one of my playlists. Part of what the playlist returns is a comma delimited list containing each video id in the playlist. I then take one of those id strings and pass it to getEntry() with detailed set to 'true'. I'm hoping it will return an Entry array contain thumbnail, link, and any associated text of the video itself. However, I get an error similar to the following:

          'code' => string 'INVALID_KS' (length=10)
          'desc' => string 'Invalid KS [MDY1OTk5NWQ3Y .. <snipped>  .. uYW1lO2VkaXQ6Kg==]. Error [-4,INVALID_TYPE]' (length=170)

Here is my code (my partner_id,secret code stripped out). It has a ton of debug statements, especially firephp code.
Here is the live link: http://mcc-webdev-v01.mcc-anthill.net/~kdpsand/kal/kal1/expkfor.php

<?php

require_once('FirePHPCore/FirePHP.class.php');
ob_start();
global $firephp;
$firephp = FirePHP::getInstance(true);
require_once("kaltura_client.php");

global $client;
global $user;
global $detailed;
global $page;
global $page_size;

function getMyPlayList($playlistid){
        global $client;
        global $user;
        global $firephp;
        $firephp->log($playlistid, "getMyPlayList -- Passed In:");

        $detailed = true;

        $res = $client->getPlaylist ( $user , $playlistid , $detailed );
        $count = @$res["result"]["count"];
        $entries = @$res["result"]["playlist"];
        $firephp->log($entries, "Inside getMyPlayList-entries:");
        $firephp->log($res, "Inside getMyPlayList-res:");
//      $plitemsarr = split(",",$entries['dataContent']);
//echo "gp- item0: " .$plitemsarr[0]. "<br/>";
//      $mydetaileditem = $client->getEntry ( $user, $pitem, $detailed);
//var_dump($mydetaileditem);
        return $entries;

}

function getMyEntry($myentry){

        global $client;
        global $user;
        global $firephp;

        $firephp->log($myentry, "getMyEntry -- Passed In:");

        $detailed = true;
        $mydetaileditem = $client->getEntry ( $user, $pitem, $detailed);
        return $mydetaileditem;

}

$userId = "username";
$partnerId = "--partnerid--";
$subPartnerId = "--subpartnerid--";
$secret = "--secret--";
$adminsecret = "--adminsecret--";
$host = "www.kaltura.com";
$mix_name = "Mix Title";
//$filtered_entries = "the_admin_tag_you_set_in_the_kmc";
$filtered_entries = "--snipped--";
$playlistid = "--snipped--";

$config = new KalturaConfiguration($partnerId, $subPartnerId);
$config->serviceUrl = $host;
$client = new KalturaClient($config);
$user = new KalturaSessionUser();
$user->userId = $userId;
$result = $client->startSession($user, $adminsecret, true, "edit:*");
$sessionId = @$result["result"]["ks"];
//echo "dumping result<br/>";
//print_r($result);
//echo "<br/><br/>";
$client->setKS($sessionId);

//$firephp->log($sessionId, "Session ID");
// playlist
$firephp->trace('Made it here playlist dump');
$plresults = getMyPlayList($playlistid);
$firephp->log($plresults, 'plresults');

$firephp->log($plresults['dataContent'], 'dataContent');
//$plitems = $plresults['dataContent'];
$plitemsarr = split(",",$plresults['dataContent']);
//echo "<br/><br/>item0: " .$plitemsarr[0]. "<br/>";
//var_dump($plitemsarr);
echo "<br/><br/>";
$mydetaileditem = getMyEntry($plitemsarr[0]);
var_dump($mydetaileditem);
echo "<br/><br/>";

?>

So, anyway, there it is. Any help or nudge you can provide will be greatly appreciated.
Thanks,
Keith

Joined: 04/05/2009
Points: 354

Normally the INVALID_TYPE error message comes up when you're using an admin session when you should actually be using a user session or vice versa.

My suggestion would be to test out the API using the TestMe console, and once you've got that working fine, then you can start coding away...

Joined: 01/05/2009
Points: 1697

Hi Keith,

As I showed you on the email as well, the problem is actually with your getMyEntry function -

function getMyEntry($myentry){
        global $client;
        global $user;
        global $firephp;
        $firephp->log($myentry, "getMyEntry -- Passed In:");
        $detailed = true;
        $mydetaileditem = $client->getEntry ( $user, $pitem, $detailed);
        return $mydetaileditem;
}

where you get the parameter $myentry as an input, but provide a non-existing parameter ($pitem) to the $client->getEntry call.

So, replacing this line: $mydetaileditem = $client->getEntry ( $user, $pitem, $detailed);
with this line: $mydetaileditem = $client->getEntry ( $user, $myentry, $detailed); will solve the problem.