GithubHelp home page GithubHelp logo

arm092 / youtuber-for-laravel Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 4.0 13 KB

The package will help you to upload videos to youtube with privacy parameter

License: MIT License

PHP 100.00%
laravel uploading-videos youtube-uploader php youtube youtube-api laravel6 laravel-6 laravel-6-package upload

youtuber-for-laravel's Introduction

Youtube Uploader for Laravel

laravel youtube uploader is a php package written by Arman Khachatryan with laravel to handle many youtube sdk functionality by making it's api more easy.

Features

  • Uploading videos to user channel
  • Creating playlists
  • Insert video to existing playlist
  • Set thumbnail to existing video or at uploading video
  • Deleting video

Installation Guide

At laravel project install package using composer

composer require arm092/youtuber-for-laravel

The package is compatible with Laravel 6.x so you don't need to set providers or aliases for the package, we're using laravel auto discovery

Get Your Credentials From Google

  • Go to Google Developers Console Press Credentials from the sidebar then create project from OAuth consent screen then Click Credentials => Create credentials => OAuth client id, choose it web application and set you Authorized redirect URIs, also you can edit or add new urls later
  • You will get Client Id and Client Secret
  • Go to your .env file and paste your credentials to be like this
GOOGLE_CLIENT_ID=YOUR_CLIENT_ID
GOOGLE_CLIENT_SECRET=YOUR_SECRET

You are now ready to use the package

There is two steps to do any thing for the package, get authenticated url and do the youtube api action

To get the auth url, just go to routes/web.php and do this route or the path you want to use

Route::get('youtube/auth', 'YoutubeUploaderController@auth');

At the controller, you will get the url and you can show it in view file or redirect user to it directly

use Youtube;
public function auth() {
    $redirect_url ='http://localhost/youtube-uploader/public/youtube/callback';  // Upload video path

    return redirect(Youtube::setRedirectUrl($redirect_url)->AuthUrl());
  }

This code will authenticate user then redirect user to another url to do your logic on it, and to do any logic code, you need to add route url to routes/web.php

Route::get('youtube/callback', 'YoutubeUploaderController@callback');

Don't forget to save full path of callback url at google console developer at credential for project

The we will now show our logic of the package

Upload video

public function callback(Request $request) {
      $redirect_url ='http://localhost/youtube-uploader/public/youtube/callback';
      $video = public_path('VIDEO_FILE');
      $image = public_path('IMAGE_FILE');
    	$youtube = Youtube::setRedirectUrl($redirect_url)->upload($video,
            [
                'title' => 'TITLE',
                'description' => 'DESCRIPTION',
                'tags' => ['tag 1', 'tag 2'],
                'category_id' => '22',
                'privacy' => 'public' // or 'private' and 'unlisted'
            ]
        );

      // Get uploaded video id
      $video_id = $youtube->uploadedVideoId();
}

Set thumbnail to existing video

Remember that you need to set auth url at routes for each callback url

public function another_callback(Request $request) {
    $redirect_url ='http://localhost/youtube-uploader/public/youtube/callback/another_callback';
    $video_id = 'VIDEO_ID';
    $image = public_path('THUMBNAIL_PATH');
    $youtube = Youtube::setRedirectUrl($redirect_url)->updateThumbnail($video_id, $image);
}

Set thumbnail at uploading

Remember that you need to set auth url at routes for each callback url

public function another_callback(Request $request) {
      $redirect_url ='http://localhost/youtube-uploader/public/youtube/callback/another_callback';
      $video = public_path('VIDEO_PATH');
      $image = public_path('THUMBNAIL_PATH');
      $youtube = Youtube::setRedirectUrl($redirect_url)->upload($video,
             [
                 'title' => 'TITLE',
                 'description' => 'Description1',
                 'tags' => ['tag 1', 'tag2'],
                 'category_id' => '22',
                 'privacy' => 'public' // or 'private' and 'unlisted'
             ]
         )->withThumbnail($image);
  
         $video_id = $youtube->uploadedVideoId();
}

Set tags for existing video

Remember that you need to set auth url at routes for each callback url

public function another_callback(Request $request) {
       $redirect_url ='http://localhost/youtube-uploader/public/youtube/callback/another_callback';
       $video_id = 'YOUR_VIDEO_ID';
       $youtube = Youtube::setRedirectUrl($redirect_url)->updateTags($video_id, ['tag 1', 'tag2', 'Tag3', 'Tag 4']);
}

Create Playlist

Remember that you need to set auth url at routes for each callback url

 public function another_callback(Request $request) {
       $redirect_url ='http://localhost/youtube-uploader/public/youtube/callback/another_callback';
       $youtube = Youtube::setRedirectUrl($redirect_url)
                         ->createPlaylist('TITLE', 'DESCRIPTION');
 
       // Get playlist id
       $playlist_id = $youtube->createdPlaylistId();
 }

Insert Video to playlist

Remember that you need to set auth url at routes for each callback url

 public function another_callback(Request $request) {
     $redirect_url ='http://localhost/youtube-uploader/public/youtube/callback/another_callback';
     $youtube = Youtube::setRedirectUrl($redirect_url)
                       ->VideoToPlaylist('VIDEO_ID', 'PLAYLIST_ID');    
 }

Delete video by the given id

Remember that you need to set auth url at routes for each callback url

public function another_callback(Request $request) {
    $redirect_url ='http://localhost/youtube-uploader/public/youtube/callback/another_callback';
    $video_id = 'VIDEO_ID';
    $youtube = Youtube::setRedirectUrl($redirect_url)->deleteVideo($video_id);
}

youtuber-for-laravel's People

Contributors

arm092 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

youtuber-for-laravel's Issues

i have an error

hello sir ,
when i use first step when i call youtube/auth , after signing in , it redirect back and show me this error

Capture

the error is : " GuzzleHttp\Exception\ClientException
Client error: POST https://oauth2.googleapis.com/token resulted in a 400 Bad Request response: { "error": "redirect_uri_mismatch", "error_description": "Bad Request" } " .

i put the second route with method ( callback ) and the error i think from third line

public function callback(Request $request){

    $redirect_url ='http://localhost/proj/public/youtube/callback';
    $video = puplic_path('video\1.mp4');    // i made a folder called video and put one from my computer

> $youtube = Youtube::setRedirectUrl($redirect_url)->upload($video,[]);`

    // Get uploaded video id
    return   $video_id = $youtube->uploadedVideoId();
}

what should i do ?

thanks sir .

Get VideoId

Hello sir, i want to ask,
How do I get a videoid when i want to upload a video to a playlist?

Upload thumbnail and video using remote url?

We store our mp4 videos in Amazon S3. With Vimeo, we can simply provide an url to the remote mp4 file and thumbnail to upload to Youtube without having to download it to the webserver an then reupload to youtube. Is this possible to do this with your solution and/or the youtube api or does it require local files?

Thanks!

Use as Job?

Pardon my ignorance, but I am trying to implement this laravel Job to be used with an API I am building out for our internal video syncing system. Is it possible to do that or does it require some frontend controller requirements? Im trying to keep things simple and the controller/callback requirements are throwing me for a loop a bit.

Basically my api receives a POST from a third party api that gives the video mp4 url, title, description and I need to be be able to add this upload job into a laravel job queue. I have everything completed for doing this with vimeo, but they have no token requirements and its api is a bit more straight forward. No need for session tokens, etc.

Any advice on this is sincerely appreciated. Maybe this package isnt the right one for the job?

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.