2
votes

I use youtube API to update video on youtube. The problem is that i got this error from youtube when i want to update the video publishAt status.

[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."
 }
}

But the strange thing is that i get the error only if i set the publishAt value (ive updated the privacyStatus to 'private'). If the publishAt is null the update process is successful.

$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;
}

ive search the internet about this problem but didnt found any solution. Please help thanks.

Note: using this code, upload video is successful.

2

2 Answers

1
votes

To my research following are couple of possibilities that can cause the error -

  • status.publishAt property can only be set if the video's privacy status is private and the video has never been published.

  • Setting the status.publishAt too close to the current time. Try 60 minutes. Reference

1
votes

The following comes directly from the documentation PublisedAt

The date and time when the video is scheduled to publish. It can be set only if the privacy status of the video is private. The value is specified in ISO 8601 (YYYY-MM-DDThh:mm:ss.sZ) format. Note the following two additional points about this property's behavior:

  1. If you set this property's value when calling the videos.update method, you must also set the status.privacyStatus property value to private even if the video is already private.

  2. If your request schedules a video to be published at some time in the past, the video will be published right away. As such, the effect of setting the status.publishAt property to a past date and time is the same as of changing the video's privacyStatus from private to public.