Create an video gallery with UStream API - api

I'm trying to create a simple video gallery that pulls the videos from the recorded shows of a specific Ustream user. I've been doing some research and looking at the API Documentation but can't seem to figure it out.
This is what I have so far.
$request = 'http://api.ustream.tv';
$format = 'php'; // this can be xml, json, html, or php
$args .= 'subject=[channel]';
$args .= '&uid= [the-crossfader-show]';
$args .= '&command=[getCusomEmbedTag]';
$args .= '&params=[autoplay:false; mute:false; height:100; width:100;]';
$args .= '&page=[1]';
$args .= '&limit=[20]';
$args .= '&key=[4872929558631FEB4E9AEE8DDF080F28]';
// Get and config the curl session object
$session = curl_init($request.'/'.$format.'?'.$args);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
//execute the request and close
$response = curl_exec($session);
curl_close($session);
// this line works because we requested $format='php' and not some other output format
$resultsArray = unserialize($response);
// this is your data returned; you could do something more useful here than just echo it
print_r $resultsArray['result'];
I'm not really sure what to do after this to turn it into a simple gallery. Anyone have any experience with the UStream API or have suggestions on what to do next?

I know this is an old post, but I have been looking into the API myself for the first time today and came across this. Try using arguments without the square brackets around your values? example:
$args .= 'subject=channel';
$args .= '&uid=the-crossfader-show';
$args .= '&command=getCusomEmbedTag';
$args .= '&params=autoplay:false; mute:false; height:100; width:100;';
$args .= '&page=1';
$args .= '&limit=20';
$args .= '&key=4872929558631FEB4E9AEE8DDF080F28';
You also had an extra space before the-crossfader-show. I haven't tried this code, but perhaps this will help. Also, setting subject=user would get you all the videos for a user, vs subject=channel which i believe to only be a single video stream?

Related

remove alias using google php api

Is it possible to remove a user's alias using a service account and the google php api?
I have tried several methods, including:
$optParams = array('alias'=>$userMail);
$remove_alias = $directory_service->users->delete($user_info['primaryEmail'],$optParams);
$remove1 = $directory_service->getAuth()->authenticatedRequest($remove_alias);
AND
$url = "https://www.googleapis.com/admin/directory/v1/users/" . $user_info['primaryEmail'] . "/aliases/" . $userMail;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$request_headers = array();
$request_headers['Content-type'] = 'application/json';
curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$output = curl_exec($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($output, 0, $header_size);
$body = substr($output, $header_size);
curl_close($ch);
I get either error 401, Login Required. Or error, unidentified 'alias'
It looks like calling users->delete vs users_aliases->delete might be causing the issue. Maybe something like this would work?
require_once $CLIENT_API_PATH . '/vendor/autoload.php';
date_default_timezone_set('America/Los_Angeles');
// this is the service account json file used to make api calls within the domain
$serviceAccount = $JSON_PATH . '/service-account-creds.json';
// delegate the work to an account with ability to make changes
$impersonateUser = 'adminWithRolesToMakeChanges#your.domain.com';
// these are the scope(s) used.
define('SCOPES', implode(' ', array( Google_Service_Directory::ADMIN_DIRECTORY_USER_ALIAS ) ));
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $serviceAccount );
$client = new Google_Client();
// loads the json service account file.
$client->useApplicationDefaultCredentials();
$client->setScopes(SCOPES);
$client->setSubject($impersonateUser);
$dirObj = new Google_Service_Directory($client);
// This is the user account to delete the alias from
$userKey = 'joeschmo#your.domain.com';
$alias = 'alias2delete#your.domain.com';
$aliasObj = new Google_Service_Directory_Alias( array( 'alias' => $alias ) );
// delete the alias from the account.
$results = $dirObj->users_aliases->delete($userKey, $aliasObj);
// If successful, this method returns an empty response body.
print_r($results);
See Also:
https://developers.google.com/admin-sdk/directory/v1/reference/users/aliases/delete

eBay Finding API filter by shipToLocations

I'm using eBay Finding API and I want to get results by filtering shipping to my country. I found this shipToLocations, but I can't find the filter.
$apicall .= "&itemFilter(0).name=Condition";
$apicall .= "&itemFilter(0).value=New";
$apicall .= "&itemFilter(1).name=ListingType";
$apicall .= "&itemFilter(1).value=FixedPrice";
$apicall .= "&itemFilter(2).name=HideDuplicateItems";
$apicall .= "&itemFilter(2).value=true";
You can set a new itemFilter with name=AvailableTo and value=<2 Characters code of your country>
For example:
$apicall .= "&itemFilter(1).name=AvailableTo";
$apicall .= "&itemFilter(1).value=DE"; // DE = country code for Germany

Joomla 3.0 not echoing usertype

I made the following code to get some user variables in a flash app:
<?php
$user =& JFactory::getUser();
echo $user->get('username') ;
echo $user->get('id') ;
echo $user->get('name') ;
echo $user->get('usertype') ;
?>
Everything but usertype works, for some reason. Usertype is vital to be able to monetize my app. I followed this as a reference, so it seems alright:
http://docs.joomla.org/Accessing_the_current_user_object
Whats wrong here?
Right, I've had a look around and I can't actually find a decent solution that simply provides you with the name of the group that the user belongs to. Everything else gives you an array or the ID, so I have written a simple function that will get you exactly what you want:
function getUserGroup($userId){
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('title')
->from('#__user_usergroup_map AS map')
->where('map.user_id = '.(int) $userId)
->leftJoin('#__usergroups AS a ON a.id = map.group_id');
$db->setQuery($query);
$result = $db->loadResult();
return $result;
}
echo getUserGroup($user->id);
Hope this helps

JSON respone from CURL request from HTTP API - HTML transform

I am able to send the CURL request to a test http API and getting the response as well.
My CURL request is like:
$request = "";
$param['auth-userid'] = '449735';
$param['api-key'] = 'apikey';
$param['domain-name'] ='sambalpurodisha';
$param['tlds']='com';
foreach ($param as $key => $val) {$request.= $key ."=".urlencode($val);
$request .="&";}
$request=substr($request,0,strlen($request)- 1 );
$url = "https://test.httpapi.com/api/domains/available.json?".$request;
$ch = curl_init($url);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$result = curl_exec( $ch );
curl_close( $ch );
I am getting a response like:
{"sambalpurodisha.com":{"status":"available","classkey":"domcno"}}
Now I have tried everything to format the result in more readable manner like
Domain - sambalpurodisha.com is available for purchase.
I have tried number of suggestions here at stack, but none worked for me. A direction where I can look for
You'll need to decode the returned JSON string as either a JSON object or an associative array, then iterate through it:
$rawJSON = '{"sambalpurodisha.com":{"status":"available","classkey":"domcno"}}';
$jsonArray = json_decode($rawJSON, true);
foreach($jsonArray as $key => $val) {
echo 'Domain: ' . $key . ' status: ' . $val['status'] . "\n";
}

php/Drupal - list all nodes that a given user to permission to edit

I have a function that lists all nodes on the system. I would like to refine this to show only nodes that current user is able to edit - either with API or SQL statement. (Drupal 6)
function fnGetNodeTypes($typeOfNodes) {
$string = "";
$types_of_nodes = array_keys(node_get_types());
$string .= "<select name='typeOfNodes'>";
$string .= "<option value=''>Please select</option> ";
$string .= "<option value='all'>All</option> ";
foreach($types_of_nodes as $node){
if($typeOfNodes == $node ){
$selected = "selected";
}
else{
$selected = "";
}
$string .= "<option $selected value=\"" . $node . "\">" . $node ;
$string .= "</option>\n";
}
$string .= "</select\n>";
return $string;
}
Update:
Following #chx suggestion I tried messing around with users, users_roles and permissions. Let me know if there is a more Drupal way of doing this.
//----------------------------------------------
// Contruct select/option box of node types
//----------------------------------------------
function fnGetNodeTypes($typeOfNodes) {
$string = "";
$types_of_nodes = array_keys(node_get_types());
$string .= "<select name='typeOfNodes'>";
$string .= "<option value=''>Please select</option> ";
//$string .= "<option value='all'>All</option> ";
foreach($types_of_nodes as $node_type){
if (fnInArray($node_type))
{
if($typeOfNodes == $node_type ){
$selected = "selected";
}
else{
$selected = "";
}
$string .= "<option $selected value=\"" . $node_type . "\">" . $node_type ;
$string .= "</option>\n";
}
}
$string .= "</select\n>";
return $string;
}
//---------------------------------------------------------------------
// function fnInArray - see if user is allowed to edit this node type
//---------------------------------------------------------------------
function fnInArray($node_type)
{
global $user;
if ($user->name == 'admin') { return TRUE; }
// get list of all nodes that user is allowed to access
//
$string = " SELECT permission.perm as permission_perm " .
" from users " .
" join users_roles on ( users_roles.uid = users.uid ) " .
" join permission on (permission.rid = users_roles.rid) " .
" where users.name = '" . $user->name . "'";
$result = db_query($string);
while ($row = db_fetch_object($result)) {
$pieces = explode(", " , $row->permission_perm);
$node_name = "edit any " . trim($node_type) . " content";
if (in_array($node_name, $pieces ))
{
return TRUE;
}
return FALSE;
}
}
This is fairly impossible to do. Node access can be specified by a hook so the only generic way to do that would be to retrieve every. single. node. and run node_access($node, 'update') on them. That's not too fast. You can mess around with node types, permissions, the node access table etc depending on how your site is set up and modules are used. If we presume that the only thing controlling your nodes are the permissions and understand please this presumption is not always true by far, then in Drupal 6 and below (I suspect from node_get_types() you are not using D7) you would indeed iterate over node_get_types()and check user_access("edit own $type content") || user access("edit any $type content") but this won't go too far.
Not quite sure of the proper method for Drupal 6 (check db_rewrite_sql) but for Drupal 7, while you are building your query add addTag('node_access') to the query and that will limit it to only nodes that the user has permission to edit. If you go to the link for db_rewrite_sql above make sure to take a look at the comments.
db_query + db_rewrite_sql: Returns only the rows the logged-in user is allowed to view.
$results = db_query(db_rewrite_sql($query), $args);
This is what the Module Grants Monitor module is for http://drupal.org/project/module_grants. From the project page: "Clicking on it reveals a summary of all the content the logged-in user has access to (i.e. view, edit) after access controls have been applied by the content access modules installed on your site". I installed and tested this today and it seems to work. Does anyone have comments or experience with this module?
It seems like this should also be possible with Views or Rules... but maybe that's just because everything seems possible with them...