Getting different video ids YouTube - php

code.google.com's API for PHP
I have used this function : function printVideoEntry($videoEntry) and got
Video ID: XXXXXXXXXXXXXXXXXXXXXXXXXX Watch page:
http://www.youtube.com/watch?v=YYYYYYYYYYYYYY&feature=youtube_gdata_player
Flash Player Url:
http://www.youtube.com/v/YYYYYYYYYYYYY?version=3&f=playlists&app=youtube_gdata
If I pass given video id it gives me error:
Uncaught exception 'Zend_Gdata_App_HttpException' with message
'Expected response code 200, got 400 Invalid id'
And if I pass YYYYYYYYYYYYYYYYY from Watch page and Flash Player Url [both are same] I'm getting it what I need.
Help is much appreciated, Thanks in advance.
Using this function for getting video entries
function printVideoEntry($videoEntry) {
echo "<div onclick=\"ytvbp.presentVideo('".$videoEntry->getVideoId()."')\" >";
echo 'Video: '.$videoEntry->getVideoTitle() . "<br>";
echo "</div>";
echo 'Video ID: ' . $videoEntry->getVideoId() . "<br>";
echo 'Watch page: ' . $videoEntry->getVideoWatchPageUrl() . "<br>";
echo 'Flash Player Url: ' . $videoEntry->getFlashPlayerUrl() . "<br>";
}
I'm calling print video function from
function getAndPrintPlaylistVideoFeed($playlistListEntry) {
$yt = new Zend_Gdata_YouTube();
$playlistVideoFeed = $yt->getPlaylistVideoFeed($playlistListEntry->getPlaylistVideoFeedUrl());
foreach ($playlistVideoFeed as $playlistVideoEntry) {
$getandprintplaylistvideofeed_array[] = printVideoEntry($playlistVideoEntry);
}

$videoEntry should be a VideoEntry-object, which you can get based on an ID:
$videoEntry = $yt->getVideoEntry('the0KZLEacs');
Then you could call the function and set that as a parameter:
printVideoEntry($videoEntry);
Or you could edit the first lines of printVideoEntry:
function printVideoEntry($videoId) {
$videoEntry = $yt->getVideoEntry('the0KZLEacs');
//...
}
Check out the docs to see what information you can squeeze out of a VideoEntry =)

Related

firestore display values of data in php

how to display each record's values?
$collectionReference = $this->fsdb->collection('orders');
$documentReference = $collectionReference->document('MSKpcuedwxNmdLn2Ydsp');
$snapshot = $documentReference->snapshot();
echo "Hello " . $snapshot['userId'];
I am receiving this error:
ErrorException
Object of class Google\Cloud\Firestore\DocumentReference could not be converted to string
print_r() function works correctly but how to access each individual record?
I have been searching for hours to get this solved but I found no reference on web
Please help me in here...
A snapshot contains both data and metadata about the document. To get the data you need to call its data() method:
$collectionReference = $this->fsdb->collection('orders');
$documentReference = $collectionReference->document('MSKpcuedwxNmdLn2Ydsp');
$snapshot = $documentReference->snapshot();
if ($snapshot->exists()) {
printf('Document data:' . PHP_EOL);
echo "Hello " . $snapshot->data()['userId'];
} else {
printf('Document %s does not exist!' . PHP_EOL, $snapshot->id());
}
Also see the Firebase documentation on getting a document from Firestore.

Zend Framework : What is difference between partial and render view? How to use global variable in partial?

Basically, I know difference bween Partial and Render View but I need more details and how can I solve below problem.
In view.phtml template, I have written below code.
foreach($this->pageUserActivity as $pageUserActivityItem) {
switch ($pageUserActivityItem->activityType) {
case 'likecommentcast':
echo $this->partial('activity/_likecommentcast.phtml', array('activityItem'=>$pageUserActivityItem,'loggedInUser'=>$this->loggedInUserStd, 'pageType' => $this->pageType));
break;
case 'cast':
echo $this->partial('activity/_cast.phtml', array('activityItem'=>$pageUserActivityItem,'loggedInUser'=>$this->loggedInUserStd, 'pageType' => $this->pageType));
break;
case 'castcomment':
echo $this->partial('activity/_castcomment.phtml', array('activityItem'=>$pageUserActivityItem,'loggedInUser'=>$this->loggedInUserStd, 'pageType' => $this->pageType));
break;
}
}
Now, if activity has youtube link then I need to fetch data using Zend_Gdata_ClientLogin::getHttpClient & Zend_Gdata_YouTube and embed data as below.
$email = Zend_Registry::get('config')->google->email;
$passwd = Zend_Registry::get('config')->google->password;
try {
$client = Zend_Gdata_ClientLogin::getHttpClient($email, $passwd, Zend_Gdata_YouTube::AUTH_SERVICE_NAME);
} catch (Zend_Gdata_App_CaptchaRequiredException $cre) {
echo 'URL of CAPTCHA image: ' . $cre->getCaptchaUrl() . "\n";
echo 'Token ID: ' . $cre->getCaptchaToken() . "\n";
} catch (Zend_Gdata_App_AuthException $ae) {
echo 'Problem authenticating: ' . $ae->exception() . "\n";
}
$youtube = new Zend_Gdata_YouTube($client,'{API_KEY}');
I have above code in all three files (activity/_cast.phtml, activity/_likecommentcast.phtml, activity/_castcomment.phtml) but this makes script slow as I am calling login api all time. I want such that any of activity already has youtube link and we already initiated $client and $youtube then use it again if further feed has youtube link instead of initiating $client and $youtube again and again.

Getting video upload date with Zend Gdata Youtube API

I'm trying to get a list of videos for a specific user with all the details for the video (title, desc., date, tags...)
I can get pretty much everything I need, but can't figure out how to get the upload date.
I tried using getVideoRecorded() and getRecorded(), but both return nothing.
I can't seem to find anything related to this on Google, all I can find is class references which tell me that I have to use getVideoRecorded or getRecorded, but nothing more.
Am I doing something wrong? how can I get the upload date?
Current code:
$authenticationURL= 'https://www.google.com/accounts/ClientLogin';
$httpClient =
Zend_Gdata_ClientLogin::getHttpClient(
$username = $yt_username,
$password = $yt_password,
$service = 'youtube',
$client = null,
$source = '', // a short string identifying your application
$loginToken = null,
$loginCaptcha = null,
$authenticationURL);
$yt = new Zend_Gdata_YouTube($httpClient);
$feed = $yt->getUserUploads($yt_username);
foreach($feed as $item)
{
echo "<div>";
echo "<h4>title: " . $item->getVideoTitle() . "</h4>";
echo "<p>id: " . $item->getVideoId() . " | ";
echo "upload date: " . $item->getVideoRecorded() . "</p>";
echo "<p>description: " . $item->getVideoDescription() . "</p>";
echo "<p>tags: " . implode(", ", $item->getVideoTags()) . "</p>";
echo "</div>";
echo "<hr>";
}
You can try and extract the < published > or < updated > tags from the following xml:
http://gdata.youtube.com/feeds/api/videos/{$videoId}

PHP Google API Client v3 get contacts

I still have trouble with the new google_api_client php library. I'm trying to retrieve the user's contacts.
I'm very close to the right solution ... I mean, I just got all the results but a can't parse it.
Probably it's because I'm not strong with XML parser. After tests and tests ... I get this solution (based on the example file by Google):
...
$req = new apiHttpRequest("https://www.google.com/m8/feeds/contacts/default/full");
$val = $client->getIo()->authenticatedRequest($req);
$response = simplexml_load_string($val->getResponseBody());
foreach($response->entry as $entry)
{
$child = $entry->children("http://schemas.google.com/g/2005");
$mail_info = $child->attributes();
}
...
In the $response I can get the title field where my contact's full name is stored, and in the $mail_info a got an object where i see the address field when I get the email address.
It's SAD and UGLY solution ... what if I want the company name, address ... phone numbers ... photos. Where are all these informations.
How can I use the Google response in a great and clean solution?
Anyone can give me some help.
Bye
What helped me was requesting JSON instead of XML. Try adding ?alt=json to the end of the URL in the request you make to google.
$req = new apiHttpRequest("https://www.google.com/m8/feeds/contacts/default/full?alt=json");
$val = $client->getIo()->authenticatedRequest($req);
$string = $val->getResponseBody();
$phparray = json_decode($string);
Certainly not child's play to get what you want but working with php arrays is probably easier.
For completeness this is the google contacts php example that we both probably found that helped us:
https://code.google.com/p/google-api-php-client/source/browse/trunk/examples/contacts/simple.php
EDIT:
Here is another link that might help. In the comments it describes a cleaner of accessing contact's data using JSON.
http://25labs.com/import-gmail-or-google-contacts-using-google-contacts-data-api-3-0-and-oauth-2-0-in-php/
$url = 'https://www.google.com/m8/feeds/contacts/default/full?max-results='.$max_results.'&alt=json&v=3.0&oauth_token='.$accesstoken;
$xmlresponse = curl_file_get_contents($url);
$temp = json_decode($xmlresponse,true);
foreach($temp['feed']['entry'] as $cnt) {
echo $cnt['title']['$t'] . " --- " . $cnt['gd$email']['0']['address'] . "</br>";
}
and
$url = 'https://www.google.com/m8/feeds/contacts/default/full?max-results='.$max_results.'&alt=json&v=3.0&oauth_token='.$accesstoken;
$xmlresponse = curl_file_get_contents($url);
$temp = json_decode($xmlresponse,true);
foreach($temp['feed']['entry'] as $cnt) {
echo $cnt['title']['$t'] . " --- " . $cnt['gd$email']['0']['address'];
if(isset($cnt['gd$phoneNumber'])) echo " --- " . $cnt['gd$phoneNumber'][0]['$t'];
if(isset($cnt['gd$structuredPostalAddress'][0]['gd$street'])) echo " --- " . $cnt['gd$structuredPostalAddress'][0]['gd$street']['$t'];
if(isset($cnt['gd$structuredPostalAddress'][0]['gd$neighborhood'])) echo " --- " . $cnt['gd$structuredPostalAddress'][0]['gd$neighborhood']['$t'];
if(isset($cnt['gd$structuredPostalAddress'][0]['gd$pobox'])) echo " --- " . $cnt['gd$structuredPostalAddress'][0]['gd$pobox']['$t'];
if(isset($cnt['gd$structuredPostalAddress'][0]['gd$postcode'])) echo " --- " . $cnt['gd$structuredPostalAddress'][0]['gd$postcode']['$t'];
if(isset($cnt['gd$structuredPostalAddress'][0]['gd$city'])) echo " --- " . $cnt['gd$structuredPostalAddress'][0]['gd$city']['$t'];
if(isset($cnt['gd$structuredPostalAddress'][0]['gd$region'])) echo " --- " . $cnt['gd$structuredPostalAddress'][0]['gd$region']['$t'];
if(isset($cnt['gd$structuredPostalAddress'][0]['gd$country'])) echo " --- " . $cnt['gd$structuredPostalAddress'][0]['gd$country']['$t'];
echo "</br>";
}

What does the insertEntry in YOUTUBE API return?

This is what we use to upload a Video to YouTube using YouTube API.
$newEntry = $yt->insertEntry($myVideoEntry, $uploadUrl, 'Zend_Gdata_YouTube_VideoEntry');
Once we upload, how can we get the unique code of the Video we just uploaded ??
What I mean is, in the url,
http://www.youtube.com/watch?v=pBI3lc18k8Q
"pBI3lc18k8Q" is the unique code for the video. So, how to get this for the video we just uploaded??
Do this code after you upload it:
// Assuming that $videoEntry is the object that was returned during the upload
$state = $videoEntry->getVideoState();
if ($state) {
echo 'Upload status for video ID ' . $videoEntry->getVideoId() . ' is ' .
$state->getName() . ' - ' . $state->getText() . "\n";
} else {
echo "Not able to retrieve the video status information yet. " .
"Please try again later.\n";
}
You've got your unique code in $newEntry! ;)

Categories