Quantcast
Channel: phpjunkie.de » PHP
Viewing all articles
Browse latest Browse all 10

Import von YouTube Favoriten per PHP API

$
0
0

In eines meiner Projekte können die User ab sofort die YouTube Favoriten in ihre eigene Videogalerie importieren. Die Funktion dazu muss mit Emailadresse, Passwort und Benutzername aufgerufen werden. Diese liest bei allen Favoriten die VideoID, die Bezeichnung und den Beschreibungstext aus. Die Funktion passiert auf der YouTube API, benötigt wird Zend GDATA – dieses kann hier heruntergeladen werden. Ergänzt werden muss der Developer Key, Client ID und Application ID.

Das Codeschnipsel dazu ist wie folgt:

function video_ytimport($email, $passwd, $benutzer) {

require_once ‘Zend/Loader.php’; // the Zend dir must be in your include_path
Zend_Loader::loadClass(‘Zend_Gdata_YouTube’);

Zend_Loader::loadClass(‘Zend_Gdata_AuthSub’);
Zend_Loader::loadClass(‘Zend_Gdata_ClientLogin’);

try {

$authenticationURL= ‘https://www.google.com/youtube/accounts/ClientLogin’;
$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
$username = $email,
$password = $passwd,
$service = ‘youtube’,
$client = null,
$source = ‘xxxx’,
$loginToken = null,
$loginCaptcha = null,
$authenticationURL);

$developerKey = ‘xxxxxx’;
$applicationId = ‘xxxxxxx’;
$clientId = ‘xxxxxxxx’;

$yt = new Zend_Gdata_YouTube($httpClient, $applicationId, $clientId, $developerKey);

$yt->setMajorProtocolVersion(2);
echo $favoritesFeed = $yt->getUserFavorites($benutzer);

$anz = printVideoFeed($favoritesFeed);
return $anz;

} catch (Exception $e) {
return “login”;
}
}

function getAndPrintVideoFeed($location = Zend_Gdata_YouTube::VIDEO_URI) {

$yt = new Zend_Gdata_YouTube();
// set the version to 2 to receive a version 2 feed of entries
$yt->setMajorProtocolVersion(2);
$videoFeed = $yt->getVideoFeed($location);
printVideoFeed($videoFeed);
}

function printVideoFeed($videoFeed) {

$count = 1;

foreach ($videoFeed as $videoEntry) {
printVideoEntry($videoEntry);
$count++;
}
return $count;
}

function printVideoEntry($videoEntry) {

$bezeich = $videoEntry->getVideoTitle();
$code = $videoEntry->getVideoId();
$info = $videoEntry->getVideoDescription();

if ($code != “”) {

//// WAS MACHST DU MIT DEN FAVORITEN????
}
}


Viewing all articles
Browse latest Browse all 10

Latest Images





Latest Images