Giter Club home page Giter Club logo

youtube-livestream-api's Introduction

sahusoftcom/youtube-livestream-api:

PHP (Laravel) Package for Google / YouTube API of Video Live Streaming with Google Auth

Installation :

composer require sahusoftcom/youtube-livestream-api

Add Service provider to config/app.php provider's array:

SahusoftCom\YoutubeApi\LiveStreamApiServiceProvider::class

Execute the following command to get the configurations:

php artisan vendor:publish --tag='youtube-config'

Steps to create your google oauth credentials:

  1. Goto https://console.developers.google.com
  2. Login with your credentials & then create a new project.
  3. Enable the following features while creating key
    • Youtube Data API
    • Youtube Analytics API
    • Youtube Reporting API
  4. Then create API key from credentials tab.
  5. Then in OAuth Consent Screen enter the product name(your site name).
  6. create credentials > select OAuth Client ID. (here you will get client_id and client_secret)
  7. Then in the Authorized Javascript Origins section add you site url.
  8. In the Authorized Redirect URLs section add add a url which you want the auth code to return(redirect_url)
  9. You will get values (to be exact - client_id, client_secret, api_key, redirect_url)
  10. Now add these values - client_id, client_secret, api_key and redirect_url in the env file.

Setting Up the App:

Authentication and Authorization:

<?php
namespace Your\App\NameSpace;

use  SahusoftCom\YoutubeApi\AuthService;	// Add Code to call the api class
$authServiceObject = new AuthService();

# Replace the identifier with a unqiue identifier for account or channel
$authUrl = $authServiceObject->getLoginUrl('email','identifier');
  • Now you will get $authUrl, upon redirecting to the same will ask permissions and authorization access to the required channel.
  • Upon submitting the requirements, you'll get a $authcode on the loginCallback URL (redirect url added as in google console) & you might have specified in .env file.
  • Use this authcode to generate auth token as follows:
<?php
namespace Your\App\NameSpace;

use  SahusoftCom\YoutubeApi\AuthService;	// Add Code to call the api class
$authServiceObject = new AuthService();
$authToken = $authServiceObject->getToken($authcode);

Creating a Youtube Event:

<?php
namespace Your\App\NameSpace;

use  SahusoftCom\YoutubeApi\YoutubeLiveEventService;	// Add Code to call the api class
$data = array(
	"title" => "",
	"description" => "",
	"thumbnail_path" => "",				// Optional
	"event_start_date_time" => "",
	"event_end_date_time" => "",			// Optional
	"time_zone" => "",
	'privacy_status' => "",				// default: "public" OR "private"
	"language_name" => "",				// default: "English"
	"tag_array" => ""				// Optional and should not be more than 500 characters
);

$ytEventObj = new YoutubeLiveEventService();
/**
 * The broadcast function returns array of details from YouTube.
 * Store this information & will be required to supply to youtube
 * for live streaming using encoder of your choice.
 */
$response = $ytEventObj->broadcast($authToken, $data);
if ( !empty($response) ) {

	$youtubeEventId = $response['broadcast_response']['id'];
	$serverUrl = $response['stream_response']['cdn']->ingestionInfo->ingestionAddress;
	$serverKey = $response['stream_response']['cdn']->ingestionInfo->streamName;
}

Updating a Youtube Event:

<?php
namespace Your\App\NameSpace;

use  SahusoftCom\YoutubeApi\YoutubeLiveEventService;	// Add Code to call the api class
$ytEventObj = new YoutubeLiveEventService();
/**
* The updateBroadcast response give details of the youtube_event_id,server_url and server_key.
* The server_url & server_key gets updated in the process. (save the updated server_key and server_url).
*/
$response = $ytEventObj->updateBroadcast($authToken, $data, $youtubeEventId);

// $youtubeEventId = $response['broadcast_response']['id'];
// $serverUrl = $response['stream_response']['cdn']->ingestionInfo->ingestionAddress;
// $serverKey = $response['stream_response']['cdn']->ingestionInfo->streamName

Deleting a Youtube Event:

<?php
namespace Your\App\NameSpace;

use  SahusoftCom\YoutubeApi\YoutubeLiveEventService;	// Add Code to call the api class
$ytEventObj = new YoutubeLiveEventService();
/**
 * Deleting the event requires authentication token for the channel in which the event is created and the youtube_event_id
 */
$ytEventObj->deleteEvent($authToken, $youtubeEventId);

Starting a Youtube Event Stream:

<?php
namespace Your\App\NameSpace;

use  SahusoftCom\YoutubeApi\YoutubeLiveEventService;	// Add Code to call the api class
$ytEventObj = new YoutubeLiveEventService();
/**
 * $broadcastStatus - ["testing", "live"]
 * Starting the event takes place in 3 steps
 * 1. Start sending the stream to the server_url via server_key recieved as a response in creating the event via the encoder of your choice.
 * 2. Once stream sending has started, stream test should be done by passing $broadcastStatus="testing" & it will return response for stream status.
 * 3. If transitioEvent() returns successfull for testing broadcast status, then start live streaming your video by passing $broadcastStatus="live"
 * & in response it will return us the stream status.
 */
$streamStatus = $ytEventObj->transitionEvent($authToken, $youtube_event_id,$broadcastStatus);

Stopping a Youtube Event Stream:

<?php
namespace Your\App\NameSpace;

use  SahusoftCom\YoutubeApi\YoutubeLiveEventService;	// Add Code to call the api class
$ytEventObj = new YoutubeLiveEventService();
/**
 * $broadcastStatus - ["complete"]
 * Once live streaming gets started succesfully. We can stop the streaming the video by passing broadcastStatus="complete" and in response it will give us the stream status.
 */
$ytEventObj->transitionEvent($authToken,$youtube_event_id, $broadcastStatus);	// $broadcastStatus = ["complete"]

youtube-livestream-api's People

Contributors

alchemyguy avatar faizahmedfarooqui avatar shaband avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

youtube-livestream-api's Issues

Listing existing events

All documentation and even classes are focused on Starting, Creating, Stopping and Deleting a live event. Would you consider implementing a method or documentation to list existing live events? ( by date, name, time ... )

How to use this package?

ErrorException thrown with message "Undefined property: sahusoftcom\YoutubeApi\AuthService::$getLoginUrl"
image

How to use this package?
I dont understand

I have set all parameters as you suggest, when I run a test, a get a null response and nothing in my error log. What is the issue?

 $authServiceObject = new AuthService();
            $ytEventObj = new YoutubeLiveEventService();
           $authUrl = $authServiceObject->getLoginUrl('[email protected]', 'UCFnsPgB0XuT_k2323uw');
            $authcode = request('code');
            $authToken = $authServiceObject->getToken($authcode);

            $data = array(
                "title" => request('title'),
                "description" => request('description'),
                "thumbnail_path" => "", // Optional
                "event_start_date_time" => request('start_time'),
                "event_end_date_time" => request('end_time'), // Optional
                "time_zone" => "",
                'privacy_status' => "unlisted", // default: "public" OR "private"
                "language_name" => "English", // default: "English"
                "tag_array" => "Africa studies "   // Optional and should not be more than 500 characters
            );
            $response = $ytEventObj->broadcast($authToken, $data);
            dd($response); //whatever variable I return, it return null or false

Undefined offset: 0

When creating broadcast.

Keep getting this 9 times out of 10! Cannot find the source of it just yet, great work though got me started with the live api. If I find a proper fix will PR. If you know of one please let me know.
Thanks

update readme of start live and stop live

method of transitionEvent has three params
transitionEvent($token, $youtube_event_id, $broadcastStatus)
but in our docs have youtube_event_id is missing
please update readme

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.