抱歉我的英语:)
我需要从控制台脚本(cron)
将视频上传到youtube频道在官方的PHP代码示例(https://developers.google.com/youtube/v3/code_samples/php)作者提供使用OAuth,它的工作,但它需要使用浏览器进行身份验证和重定向uri(Web脚本)它对我不好,因为我使用控制台脚本没有gui和webserver。
我想我想在没有oauth2的情况下使用服务器密钥,但我是新手:) oauth允许选择频道(我的Google帐户上有很多频道)
你能帮我写一下代码:
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);