如何在使用google-youtube api php将视频上传到Youtube时设置高级设置



>我在下面创建了将视频上传到youtube的php脚本,并且可以正常上传。

我希望能够为上传的视频设置高级设置,如下所示:

  • 允许评论应为"已批准"而不是"全部"
  • 我还需要能够设置视频位置(这将来自"我的网站"中的数据库)
  • 我还需要能够设置录制日期(到日期)的上传)
  • 我也不希望视频统计信息公开可见

我已经环顾四周,但我无法从谷歌找到任何关于此的文档,我认为谷歌没有提供 API 的完整文档。

任何链接也可以。谢谢

require_once '../google_api/Google_Client.php';
require_once '../google_api/contrib/Google_YouTubeService.php';
$OAUTH2_CLIENT_ID = '514750847005.apps.googleusercontent.com';
$OAUTH2_CLIENT_SECRET = '9mvQL0NPv1zEOty0tZw71O4t';
$client = new Google_Client();
$client->setClientId($OAUTH2_CLIENT_ID);
$client->setClientSecret($OAUTH2_CLIENT_SECRET);
$redirect = filter_var('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'], FILTER_SANITIZE_URL);
$client->setRedirectUri("{$redirect}");
$youtube = new Google_YoutubeService($client);
if (isset($_GET['code'])) {
            if (strval($_SESSION['state']) !== strval($_GET['state'])) {
                die('The session state did not match.');
            }
            $client->authenticate();
            $_SESSION['token'] = $client->getAccessToken();
            header('Location: ' . $redirect);
        }
        if (isset($_SESSION['token'])) {
            $client->setAccessToken($_SESSION['token']);
        }
        if ($client->getAccessToken()) {
            try {
                $snippet = new Google_VideoSnippet();
                $snippet->setTitle($title);
                $snippet->setDescription($desc);
                $snippet->setTags($tags);
                $snippet->setCategoryId(22);
                $status = new Google_VideoStatus();
                $status->privacyStatus = "public";
                $today = date("Y-m-dTH:i:s");
                $recordingDetails = new Google_VideoRecordingDetails();
                $recordingDetails->setRecordingDate($today);
                $video = new Google_Video();
                $video->setSnippet($snippet);
                $video->setStatus($status);
                $video->setRecordingDetails($recordingDetails);
                // 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;
                // Create a MediaFileUpload with resumable uploads
                $media = new Google_MediaFileUpload('video/*', null, true, $chunkSizeBytes);
                $media->setFileSize(filesize($vd_file));
                // Create a video insert request
                $insertResponse = $youtube->videos->insert("status,snippet", $video, array('mediaUpload' => $media));
                $uploadStatus = false;
                // Read file and upload chunk by chunk
                $handle = fopen($vd_file, "rb");
                while (!$uploadStatus && !feof($handle)) {
                    $chunk = fread($handle, $chunkSizeBytes);
                    $uploadStatus = $media->nextChunk($insertResponse, $chunk);
                }
                fclose($handle);
                msg_add('suces', 'message', 'Youtube video upload was successful');
            } catch (Google_ServiceException $e) {
                $message = sprintf('<p>A service error occurred: <code>%s</code></p>', htmlspecialchars($e->getMessage()));
                msg_add('err', 'message', $message);
            } catch (Google_Exception $e) {
                $message = sprintf('<p>An client error occurred: <code>%s</code></p>', htmlspecialchars($e->getMessage()));
                msg_add('err', 'message', $message);
            }

您正在做的只是一个视频>插入通话。您正在编辑代码段、状态和录制详细信息。您可以通过将其他字段添加到视频资源来执行更多操作。

在插入之前填写视频资源的任何字段,这应该可以。

我遇到了类似的情况,我试图在插入时设置位置,但它不起作用。 我通过在逗号分隔列表(docs)中包含"recordingDetails"来正确设置位置part。 我正在使用 C#,所以对我来说它看起来像这样:

var videosInsertRequest = youtubeService.Videos.Insert(video, "snippet,status,recordingDetails", fileStream, "video/*");

从您的示例中,在 php 中看起来像

这样
$insertResponse = $youtube->videos->insert("status,snippet,recordingDetails", $video, array('mediaUpload' => $media));

允许评论应为"已批准"而不是"全部"

这似乎是一个YouTube错误:

https://code.google.com/p/gdata-issues/issues/detail?id=7664

相关内容

  • 没有找到相关文章

最新更新