4

and sorry for my English :)

I need to upload videos to youtube channel from console script (cron)

In offcial php code samples (https://developers.google.com/youtube/v3/code_samples/php) author offer to use OAuth, it's work, but it's need to use browser for auth and redirect uri (web script) it's not good for me, because I use console script without gui and webserver.

I think I want to use server key without oauth2, but I newbee :) And oauth allows to choose channel (I have a many channels on my google account)

Can you help me and write code about:

require_once 'include/Google/autoload.php';
require_once 'include/Google/Client.php';
require_once 'include/Google/Service/YouTube.php';
session_start();

$key = "MY_SERVER_KEY_HERE";
$client = new Google_Client();

$client->setDeveloperKey($key);
$client->setScopes('https://www.googleapis.com/auth/youtube');

$videoPath = "./video.mp4";

$snippet = new Google_Service_YouTube_VideoSnippet();
$snippet->setTitle("Test title");
$snippet->setDescription("Test description");
$snippet->setTags(array("tag1", "tag2"));
$snippet->setCategoryId("22");

$status = new Google_Service_YouTube_VideoStatus();
$status->privacyStatus = "public";

$video = new Google_Service_YouTube_Video();
$video->setSnippet($snippet);
$video->setStatus($status);

$youtube = new Google_Service_YouTube($client);
$insertRequest = $youtube->videos->insert("status,snippet", $video);
  • 3
    Authenticate your code once get the refresh token, save the refresh token some place use the refresh token in your cron script to get a new access token. This is the only option open to you. YouTube API doesn't support service accounts. – Linda Lawton - DaImTo Dec 15 '15 at 08:44
  • I think it is impossible, Because access token is same encode permission for modifine account (ex: Upload, delete, ....) – HoangHieu Dec 15 '15 at 08:53
  • Possible duplicate of [Upload videos to my Youtube channel without user authentication using YoutubeApi v3 and ouath2](http://stackoverflow.com/questions/19449061/upload-videos-to-my-youtube-channel-without-user-authentication-using-youtubeapi) – Edoardo Apr 06 '17 at 08:24

0 Answers0