* Created by PhpStorm.
 * User: jakublemiszewski
 * Date: 23/10/14
 * Time: 11:38
$key = file_get_contents('key.txt');
set_include_path($_SERVER['DOCUMENT_ROOT'] . '/YoutubeKTF/Google/src/Google');
require_once './Google/src/Google/Client.php';
require_once './Google/src/Google/Service/YouTube.php';

$application_name = 'digital souvenir';
$client_secret = 'ztsRQpn97aCSC6nS1fxovLqS';
$client_id = '';
$scope = array('', '', '');

$videoPath = "video/1mb.mp4";
$videoTitle = "Test";
$videoDescription = "Test upload to youtube";
$videoCategory = "testing";
$videoTags = array("youtube", "tutorial");

    // Client init
    $client = new Google_Client();

    if ($client->getAccessToken()) {

         * Check to see if our access token has expired. If so, get a new one and save it to file for future use.
        if($client->isAccessTokenExpired()) {
            $newToken = json_decode($client->getAccessToken());
            file_put_contents('key.txt', $client->getAccessToken());

        $youtube = new Google_Service_YouTube($client);

        // Create a snippet with title, description, tags and category id
        $snippet = new Google_Service_YouTube_VideoSnippet();

        // Create a video status with privacy status. Options are "public", "private" and "unlisted".
        $status = new Google_Service_YouTube_VideoStatus();

        // Create a YouTube video with snippet and status
        $video = new Google_Service_YouTube_Video();

        // Size of each chunk of data in bytes. Setting it higher leads faster upload (less chunks,
        // for reliable connections). Setting it lower leads better recovery (fine-grained chunks)
        $chunkSizeBytes = 1 * 1024 * 1024;

        // Setting the defer flag to true tells the client to return a request which can be called
        // with ->execute(); instead of making the API call immediately.

        // Create a request for the API's videos.insert method to create and upload the video.
        $insertRequest = $youtube->videos->insert("status,snippet", $video);

        // Create a MediaFileUpload object for resumable uploads.
        $media = new Google_Http_MediaFileUpload(

        //var_dump($media->setFileSize(filesize($videoPath))); /*TESTING*/
        // Read the media file and upload it chunk by chunk.
        $status = false;
        $handle = fopen($videoPath, "rb");
        while (!$status && !feof($handle)) {
            $chunk = fread($handle, $chunkSizeBytes);
            $status = $media->nextChunk($chunk);


         * Vidoe has successfully been upload, now lets perform some cleanup functions for this video
        if ($status->status['uploadStatus'] == 'uploaded') {
            // Actions to perform for a successful upload

        // If you want to make other calls after the file upload, set setDefer back to false

    } else{
        // @TODO Log error
        echo 'Problems creating the client';

} catch(Google_Service_Exception $e) {
    print "Caught Google service Exception ".$e->getCode(). " message is ".$e->getMessage();
    print "Stack trace is ".$e->getTraceAsString();
}catch (Exception $e) {
    print "Caught Google service Exception ".$e->getCode(). " message is ".$e->getMessage();
    print "Stack trace is ".$e->getTraceAsString();

Please note that all pasted data is publicly available.