corbpie/yt-api

A PHP YouTube API wrapper

1.0 2021-08-15 03:56 UTC

This package is auto-updated.

Last update: 2024-09-25 15:19:32 UTC


README

Just a PHP YouTube API wrapper for searching videos and getting channel/video/playlist data and information.

Usage

composer require corbpie/yt-api

Put your YouTube API key at line 9 of src/YTAPI.php

Use the class with:

require_once('vendor/autoload.php');

use Corbpie\YouTubeApiClass\YTAPI;

$yt = new YTAPI();

Searching videos

Search a channel

This will gets 25 videos from the NBA channel with the query "Jordan" sorted by view count

$yt->setChannelId('UCWJ2lWNubArHWmf3FIHbfcQ');
$yt->getVideoSearch('Jordan', 'viewCount', 25);

Search everywhere

Just dont set channelId to search all of YouTube (Not a channel specific)

$yt->getVideoSearch('Jordan', 'viewCount', 25);

Get latest videos from a channel

Get 25 videos sorted by date published (recent -> oldest)

$yt->setChannelId('UCWJ2lWNubArHWmf3FIHbfcQ');
$yt->getVideoSearch('', 'date', 25);

Order types:

  • date
  • rating
  • relevance
  • title
  • videoCount
  • viewCount

results amount is capped at max 50.

Video information

$yt->setVideoId('1fjhIWJSxfw');
$yt->getVideoData();

Channel information

$yt->setChannelId('UCWJ2lWNubArHWmf3FIHbfcQ');
$yt->getChannelData();

Get channel playlists (Requires channelId to have been set):

$call->getChannelPlaylistsData(50);

Playlist videos

$yt->setPlaylistId('UCWJ2lWNubArHWmf3FIHbfcQ');
$yt->getPlaylistsData();