mmg / youtube
Wrapper class for the mmg group to consume Youtube Api.
v1.0.2
2023-03-13 01:02 UTC
Requires
- google/apiclient: 2.12.1
This package is auto-updated.
Last update: 2025-09-13 06:30:56 UTC
README
Background
This is just a "wrapper class" built on top of the "Google SDK" to minimize the effort of integrating the "Youtube" api into your projects.
Pre Requisite
- Xampp/Wampp or Mamp server must be installed.
- Composer is installed and configured properly.
- Minimum PHP 7.2 (Not tested below or with later versions).
- Google Developer Console account.
Setup Google Developer Console Project
- Sign in to Google Developer Console.
- Create "New Project" usually option is available between google cloud logo and the search bar.
- Enter "Project Name" and select "Organization" depending upon your account.
- Click blue "Create" button.
- Configure "0Auth consent screen" by filling asked details and click "Save and continue" button.
-
Add the required Scopes you will be requesting from the user:
https://www.googleapis.com/auth/youtube.readonly
https://www.googleapis.com/auth/youtube.force-ssl
click "Save and continue" after adding above scopes into consent screen.
Note: If scopes are not available in your project click "Enable API & Services" button and enable "Youtube Data API" for your project. - Add "Test users" and click "Save and continue" button.
- Click "Credentials" option provided in left "Navigation Panel".
- Click "+ Create Credentials" button and choose "API Key" & copy it.
- Create "OAuth client ID" while you are on the "Credentials" page and configure "Redirect URIs".
- Click the little "Download Icon" under the heading "OAuth 2.0 Client IDs" and download config file.
- Make sure you have "API Key" and "Config JSON" file on this step.
Example Code
https://github.com/shahzaib91/youtube-wrapper-exampleSetup Library
- Run command
composer require mmg/youtube
. - Add
require __DIR__.'/vendor/autoload.php';
on top of your php file.
Functions Description
Function Name | Description |
---|---|
public function prepare($name, $scopes, $configJsonPath, $apiKey)
|
Function to config client via wrapper class |
public function getAuthUrl()
|
Function to get auth url for authentication |
public function getAccessToken($code)
|
Function to fetch access token and set it to client |
public function setAccessToken($accessTokenJson)
|
Function sets access token to google client object |
private function parseAccessTokenJson($accessTokenJson)
|
Helper function to abstractedly perform json parsing |
public function getChannelsList()
|
Function to retrieve list of available channels owned by authenticated user |
public function getVideosList($channelId, $maxItems = 12)
|
Function to retrieve list of videos |
public function getVideoDetail($videoId)
|
Function to retrieve video details |
public function getVideoComments($videoId, $maxItems = 12)
|
Function to retrieve video comments and replies |
public function getVideoComments($videoId, $maxItems = 12)
|
Function is helping in tagging right reply to right comment by id |