flavorAsset service

1 reply [Last post]
Joined: 07/15/2010
Points: 14

So I'm just starting to work with accessing the Kaltura content using the version 3.0 API. I have figured out that to use the media web service, I would write code like this to retrieve all the media entries for my account:


// Retrieve a list of media entries
$kMediaFilter = new KalturaMediaEntryFilter();
$kMediaFilter->orderBy = KalturaMediaEntryOrderBy::NAME_ASC;
$kMediaListResponse = $kalturaClient->media->listAction($kMediaFilter);

// Determine the number of *pages* that need to be retrieved to get all of the media
// items for this account.
$pageCount = intval(ceil($kMediaListResponse->totalCount/PAGE_SIZE));

// Loop through the list of media entries returned for the account.
$p = 1;
$kFilterPager = new KalturaFilterPager();
$kFilterPager->pageSize = PAGE_SIZE;
while ($p <= $pageCount) {
$kFilterPager->pageIndex = $p;
$kMediaListResponse = $kalturaClient->media->listAction($kMediaFilter,$kFilterPager);
$numMediaEntries = count($kMediaListResponse->objects);
for ($i=0; $i < $numMediaEntries; $i++) {
// NOTE: $kMediaListResponse->objects is an array of KalturaMediaEntry objects
print("Name: ".$kMediaListResponse->objects[$i]->name.'
');
print("ID: ".$kMediaListResponse->objects[$i]->id.'
');
print("Version: ".$kMediaListResponse->objects[$i]->version.'
');
print("Media type: ".$kMediaListResponse->objects[$i]->mediaType.'
');
print_r("Flavors: ".KalturaMediaType$kMediaListResponse->objects[$i]->flavorParamsIds.'
');
print('');
}
$p++;
}

In the above code the $kalturaClient is of type KalturaClient. So I came to the conclusion that I could do $kalturaClient->media->listAction(...) to use the media web service and call the list action option. This all works fine.

My question is that I'm now wanting to get the flavors for each media entry. According the API I should be able to use the flavorAsset web service and its getByEntryIdAction. But when I try to use $kalturaClient->flavorAsset->getByEntryIdAction in my PHP code's inner loop, it says the flavorAsset item doesn't exist.

Shouldn't that work? Are not all the web services in the API accessible via the KalturaClient object?

Thanks in advance,
Jack

Joined: 07/15/2010
Points: 14

So I came to the conclusion that not all the web services must be accessible through the KalturaClient.php library provided by Kaltura. So I've written some PHP code that will make the web service call. I decided to make a function that I could reuse if I need to make many service calls:


/*
* Make a web service call to Kaltura.
* Returns the XML from the Kaltura service call (or false if curl has a problem)
*/
function kalturaWebServiceCall($kalturaSession,$service,$action,$paramsArray) {
// define the list of parameters to add to the string
$getVarString = "service=$service&action=$action";
foreach ($paramsArray as $key => $value) {
$getVarString .= "&$key=$value";
}
$getVarString .= "&ks=$kalturaSession";

// Use curl to make a web service call to the Kaltura API
$resource = curl_init('http://www.kaltura.com/api_v3/?'.$getVarString);
curl_setopt($resource, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($resource);
curl_close($resource);
return $result;
}

Then I can call this in the appropriate place with something like this:


$flavorAssetsXML = kalturaWebServiceCall($kalturaSession,'flavorAsset','getByEntryId',array('entryId' => $kMediaListResponse->objects[$i]->id));

And now I just need to parse the XML and process the information.