将文件名添加到YouTube API上传



我已经为我使用API上传到YouTube的视频而获得了" RAW:UNKNOWER"文件名。查看YouTube API库,我已经看到有一个

Google_Service_YouTube_VideoFileDetails()

您可以在其中设置文件名的方法,但是当我尝试时,我会收到以下错误:

Caught Google service Exception 400 message is {
error": {
"errors": [
{
"domain": "youtube.part",
"reason": "unexpectedPart",
"message": "{0}",
"locationType": "parameter",
"location": "part"
}
],
"code": 400,
"message": "{0}"
}
} 

这是我的代码:

$snippet = new Google_Service_YouTube_VideoSnippet();
        $snippet->setTitle("Test title");
        $snippet->setDescription("Test description");
        $snippet->setTags(array("tag1","tag2"));
        $snippet->setCategoryId("27");
        $status = new Google_Service_YouTube_VideoStatus();
        $status->setPrivacyStatus('private');
        $status->setPublishAt("2019-08-13T13:13:13.1Z");
        $status->setEmbeddable(false);
        $fileDetails = new Google_Service_YouTube_VideoFileDetails();
        $fileDetails->setFileName("WI_YOUTUBE_COMMA_DESCRIPTION.mp4");
        $video = new Google_Service_YouTube_Video();
        $video->setSnippet($snippet);
        $video->setStatus($status);
        $video->setFileDetails($fileDetails);     
        $chunkSizeBytes = 1 * 1024 * 1024; 
        $client->setDefer(true);
        $insertRequest = $youtube->videos->insert("status,snippet,fileDetails", $video,
            array('onBehalfOfContentOwner' => $contentOwnerId,
                'onBehalfOfContentOwnerChannel' => $channelId));

我知道这个主题是旧的,但是如果其他人发生在同一事情中,我想节省时间。

首先,您无法在此请求中提交" Filedetails",这就是为什么您会遇到此错误的原因。noogui是正确的," slug"是解决方案,这就是您要修改代码的方式:

        $snippet = new Google_Service_YouTube_VideoSnippet();
        $snippet->setTitle("Test title");
        $snippet->setDescription("Test description");
        $snippet->setTags(array("tag1","tag2"));
        $snippet->setCategoryId("27");
        $status = new Google_Service_YouTube_VideoStatus();
        $status->setPrivacyStatus('private');
        $status->setPublishAt("2019-08-13T13:13:13.1Z");
        $status->setEmbeddable(false);
        $video = new Google_Service_YouTube_Video();
        $video->setSnippet($snippet);
        $video->setStatus($status);
        $chunkSizeBytes = 1 * 1024 * 1024; 
        $client->setDefer(true);
        $insertRequest = $youtube->videos->insert("status,snippet", $video,
            array('onBehalfOfContentOwner' => $contentOwnerId,
                'onBehalfOfContentOwnerChannel' => $channelId));
        $insertRequest = $insertRequest->withHeader("Slug", "WI_YOUTUBE_COMMA_DESCRIPTION.mp4");

此仅在将setDefer设置为true时才能起作用,否则发送请求是您拨打insert()的瞬间。

另外,withheader()返回请求的新实例。

YouTube Python API,以:

设置plug plug plug'slug'
insert_request.headers["Slug"] = fileName

相关内容

  • 没有找到相关文章

最新更新