我使用 youtube API 来更新 youtube 上的视频。 问题是当我想更新视频 publishAt 状态时,我从 youtube 收到了这个错误。
[2017-11-29 12:19:39] local.ERROR: Google_Service_Exception: {
"error": {
"errors": [
{
"domain": "youtube.video",
"reason": "invalidVideoMetadata",
"message": "The request metadata is invalid.",
"locationType": "other",
"location": "body"
}
],
"code": 400,
"message": "The request metadata is invalid."
}
}
但奇怪的是,只有当我设置 publishAt 值(我将 privacyStatus 更新为“private”)时,我才会收到错误消息。如果 publishAt 为空,则更新过程成功。
$params = array();
$part = 'snippet,contentDetails,player,status';
$properties = [
'snippet.categoryId' => $this->video->youtube_category_id,
'snippet.defaultLanguage' => '',
'snippet.description' => $this->video->video_description,
'snippet.tags[]' => !empty($this->video->tags->pluck('tag_value')->toArray())?implode(',',$this->video->tags->pluck('tag_value')->toArray()):'',
'snippet.title' => $this->video->video_title,
'status.embeddable' => true,
'status.license' => '',
'status.privacyStatus' => !empty($this->video->privacy_status) ? $this->video->privacy_status : 'private',
'status.publishAt' => empty($this->video->video_release_date) ? "" : date('Y-m-d\TH:i:s.sP',strtotime($this->video->video_release_date)),
'status.publicStatsViewable' => ''
];
if(!empty($this->video->youtube_id)){
$properties['id'] = $this->video->youtube_id;
}
$service = new \Google_Service_YouTube($client);
$propertyObject = $this->createResource($properties);
$resource = new \Google_Service_YouTube_Video($propertyObject);
if($this->upload) $client->setDefer(true);
if(!empty($this->video->youtube_id))
{
$request = $service->videos->update($part, $resource, $params);
}
elseif($this->upload)
{
$request = $service->videos->insert($part, $resource, $params);
}
else
{
exit;
}
我在互联网上搜索过这个问题,但没有找到任何解决方案。请帮忙谢谢。
注意:使用这段代码,上传视频成功。
最佳答案
根据我的研究,以下是可能导致错误的几种可能性 -
status.publishAt
属性只能在视频的隐私时设置 状态为私有(private),视频从未发布过。将
status.publishAt
设置得太接近当前时间。尝试 60 分钟。 Reference
关于php - 更新 publishAt 错误 invalidVideoMetadata - YOUTUBE v3 API PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47545477/