Thứ Năm, 24 tháng 4, 2014

YouTube Data API [Media Sharing]

The YouTube Data API allows access tYouTube content; you can use this API tfetch videos, playlists, channels, poscomments, and upload and manage videos. Users are allowed
to perform unauthenticated requests for the retrieval of feeds on popular videos, poscomments, and so on.

Some of the most frequently used YouTube API methods are listed as follows:

        getVideoFeed()Retrieve videos from a video query
        getTopRatedVideoFeed()Retrievtop-rated videos for the specific video query
        getUserUploads()Retrieve the user's uploaded videos
        getUserFavorites()Retrieve the user's favorite videos
        getVideoResponseFeed(): Get video responses for a specific video
        getVideoCommentFeed(): Gecomments for a specific video
        getPlaylistListFeed(): Get a user's playlists
        getSubscriptionFeed(): Get a user's subscriptions
        insertEntry(): Upload a video tYouTube
In this example, we will be retrieving videos for a specific keyword and then render them in the web page.
Perform the following steps for listing YouTube videos for a keyword:

1.       Create a function that will get the YouTube videos for the Zend Framework keyword.
2.       Establish the connection in a similar wato the previous connection made for Google Photos. This needs to be placed in a new method, getYoutubeVideos(), in the MediaManagerController file,src/Users/Controller/ MediaManagerController.php:
$adapter = new \Zend\Http\Client\Adapter\Curl();
$adapter->setOptions(array( 'curloptions' => array(
CURLOPT_SSL_VERIFYPEER => false,
)
)); 
$httpClient = new \ZendGData\HttpClient(); 
$httpClient->setAdapter($adapter); 
$client = \ZendGData\ClientLogin::getHttpClient( self::GOOGLE_USER_ID,
self::GOOGLE_PASSWORD,
\ZendGData\YouTube::AUTH_SERVICE_NAME,
$httpClient);

3.       Initialize the YouTube client and execute a video querfor the keyword
Zend Framework:
$yt = new \ZendGData\YouTube($client);
$yt->setMajorProtocolVersion(2);
$query = $yt->newVideoQuery();
$query->setOrderBy('relevance');
$query->setSafeSearch('none');
$query->setVideoQuery('Zend Framework');

4.     Parse the querresults and store it in an array:
$videoFeed = $yt->getVideoFeed($query->getQueryUrl(2));

$yVideos = array();
foreach ($videoFeed as $videoEntry) {
$yVideo = array();
$yVideo['videoTitle'] = $videoEntry->getVideoTitle();
$yVideo['videoDescription'] =
$videoEntry->getVideoDescription();
$yVideo['watchPage'] = $videoEntry->getVideoWatchPageUrl();
$yVideo['duration'] = $videoEntry->getVideoDuration();
$videoThumbnails = $videoEntry->getVideoThumbnails();

$yVideo['thumbnailUrl'] = $videoThumbnails[0]['url'];
$yVideos[] = $yVideo;
}
return $yVideos;
5.       The resulting content is rendered in the view and a video listing as shown in the following screenshot:


What just happened?
We have utilized the ZendGData API's YouTube APIs tretrieve a simple list of videos from YouTube for a specific keyword.
Q1. Which command is used in Composer to install a newly configured dependency?

1.       php composer.phar setup
2.       php composer.phar self-update
3.       php composer.phar show
4.       php composer.phar update


Q2. Which of the following is a valid method to upload a new photto Google Photos?

1.       uploadPhoto()
2.       insertPhoto()
3.       uploadNewPhoto()
4.       insertPhotoEntry()


Summary


In this chapterwe have learned various techniques to manage media; initially wstarted with implementing our own photgallery and later on we moved on to using Google GData APIs tretrieve and store media on the Web.

In our next chapterwe will be working on implementing a simple search interface.

Không có nhận xét nào:

Đăng nhận xét