Go to English page

ViaThinkSoft CodeLib

Dieser Artikel befindet sich in der Kategorie:
CodeLibProgrammierhilfenPHP

<?php

// Get API key:   https://console.developers.google.com/apis/credentials
// Test API here: https://developers.google.com/apis-explorer/?hl=de#p/youtube/v3/youtube.playlistItems.list

define('API_KEY''...');

function 
yt_playlist_items($playlist_id) {
    
$out = array();

    
$next_page_token '';

    do {
        
$cont file_get_contents('https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50'.(($next_page_token!='') ? '&pageToken='.urlencode($next_page_token)  : '').'&playlistId='.urlencode($playlist_id)$
        if (!
$cont) return false;

        
$obj json_decode($cont);
        if (!
$obj) return false;

        foreach (
$obj->items as $item) {
            if (
$item->snippet->resourceId->kind == 'youtube#video') {
                
$title    $item->snippet->title;
                
$video_id $item->snippet->resourceId->videoId;
                
$out[] = array($video_id$title);
            }
        }

        
$next_page_token = isset($obj->nextPageToken) ? $obj->nextPageToken '';
    } while (
$next_page_token != '');

    return 
$out;
}

// Example:
print_r(yt_playlist_items('PL9GbGAd-gY1pyxZJIX5MOdYdRbdweVAID'));

You can find more functions here.
Daniel Marschall
ViaThinkSoft Mitbegründer

Lob? Kritik? Probleme? Schreiben Sie uns!

Ihr Name (optional):

E-Mail-Adresse (optional):

Nachricht: