Google YouTube

YouTube's APIs are designed to let you integrate YouTube's video content and functionality into your website, software application, or device. You can get your developer key at your dashboard. To access YouTube services you need to grab an access token by authenticating first. The analytics scope when generating a URL can be passed by simply setting 'youtube' to getLoginURL(). Figure 1 shows how we can obtain an access token for YouTube.

Figure 1. Authentication
session_start();

$auth = eden('google')->auth('[CLIENT_ID]', '[CLIENT_SECRET]', 'http://yourwebsite.com/auth', '[API_KEY]');

//if no code and no session
if(!isset($_GET['code']) && !isset($_SESSION['token'])) {
    //redirect to login
    $login = $auth->getLoginUrl('youtube');
    header('Location: '.$login);
    exit;
}

//Code is returned back from google
if(isset($_GET['code'])) {
    //save it to session
	$access = $auth->getAccess($_GET['code']);
    $_SESSION['token'] = $access['access_token'];
	
}

When we have our token we can then access the different service levels of YouTube.

Figure 2. Instantiate YouTube
$youtube = eden('google')->youtube($_SESSION['token'], '[DEVELOPER_KEY]');
Figure 3. YouTube Methods
Method Arguments Returns Description
$youtube->activity(); none Eden_Google_Youtube_Activity Factory method for youtube activity
$youtube->channel(); none Eden_Google_Youtube_Channel Factory method for youtube channel
$youtube->comment(); none Eden_Google_Youtube_Activity Factory method for youtube comment
$youtube->contacts(); none Eden_Google_Youtube_Contacts Factory method for youtube contacts
$youtube->favorites(); none Eden_Google_Youtube_Favorites Factory method for youtube favorites
$youtube->history(); none Eden_Google_Youtube_History Factory method for youtube history
$youtube->message(); none Eden_Google_Youtube_Message Factory method for youtube message
$youtube->playlist(); none Eden_Google_Youtube_Playlist Factory method for youtube playlist
$youtube->profile(); none Eden_Google_Youtube_Profile Factory method for youtube profile
$youtube->ratings(); none Eden_Google_Youtube_Ratings Factory method for youtube ratings
$youtube->search(); none Eden_Google_Youtube_Search Factory method for youtube search
$youtube->subscription(); none Eden_Google_Youtube_Subscription Factory method for youtube subscription
$youtube->upload(); none Eden_Google_Youtube_Upload Factory method for youtube upload
$youtube->video(); none Eden_Google_Youtube_Video Factory method for youtube video

© 2012 Openovate Labs. All rights reserved.