PHP code example of lcmaquino / youtubechannel

1. Go to this page and download the library: Download lcmaquino/youtubechannel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

lcmaquino / youtubechannel example snippets




return [
    'client_id' => env('GOOGLE_CLIENT_ID', ''),
    'client_secret' => env('GOOGLE_CLIENT_SECRET', ''),
    'redirect_uri' => env('GOOGLE_REDIRECT_URI', ''),
    'youtube_channel_id' => env('YOUTUBE_CHANNEL_ID', ''),
];



namespace App\Http\Controllers\Auth;

use Lcmaquino\YouTubeChannel\YouTubeChannelManager;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class LoginController extends Controller
{
    public function redirectToProvider(Request $request)
    {
        $ytm = new YouTubeChannelManager(config('googleoauth2'), $request);

        return $ytm->redirect();
    }

    public function handleProviderCallback(Request $request)
    {
        $ytm = new YouTubeChannelManager(config('googleoauth2'),  $request);
        
        $user = $ytm->user();

        if(empty($user)) {
            //user not authenticaded

            //do something
        }else{
            //user authenticaded

            $subscribed = $ytm->isUserSubscribed();

            if ($subscribed === null) {
                //something went wrong

            } else {
                if ($subscribed) {
                    //user subscribed

                    //do something
                } else {
                    //user not subscribed

                    //do something
                }
            }
        }
    }
}



namespace App\Http\Controllers\Auth;

use YouTubeChannel;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class LoginController extends Controller
{
    public function redirectToProvider(Request $request)
    {
        return YouTubeChannel::redirect();
    }

    public function handleProviderCallback(Request $request)
    {       
        $user = YouTubeChannel::user();

        if(empty($user)) {
            //user not authenticaded

            //do something
        }else{
            //user authenticaded

            $subscribed = YouTubeChannel::isUserSubscribed();

            if ($subscribed === null) {
                //something went wrong

            } else {
                if ($subscribed) {
                    //user subscribed

                    //do something
                } else {
                    //user not subscribed

                    //do something
                }
            }
        }
    }
}