Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Youtube API - The request metadata specifies an invalid video description

I know this question is duplcated, but the phenomena is different.

I use Youtube API PHP to upload my videos. Unfortunately, its caught errors:

{
    "status": "fail",
    "mess": "Failed to start the resumable upload (HTTP 400: youtube.video, The request metadata specifies an invalid video description.)"
}

I checked the description. Use mb_strlen() return result less than 5000 characters.

$title = mb_substr($title, 0, 100);
$description = mb_substr($description , 0, 4999);
$tags = array_slice($tags, 0, 15);

$snippet = new Google_Service_YouTube_VideoSnippet();
$snippet->setTitle($title);
$snippet->setDescription($description);
$snippet->setTags($tags);
$snippet->setCategoryId("22");

$status = new Google_Service_YouTube_VideoStatus();
$status->privacyStatus = "public";

$video = new Google_Service_YouTube_Video();
$video->setSnippet($snippet);
$video->setStatus($status);

Have some special characters exist: <>, |, ' (single qoute), (), ?, " (double quote).
I researched about this error, but not any results :(

like image 778
Thanh Dao Avatar asked May 26 '17 02:05

Thanh Dao


People also ask

Why is YouTube API key not valid?

Your API key may not be working because you're using it for the wrong project. Be sure you're using the key for the project that you created it for, especially if you created multiple projects at the same time. If it's still not working, consider creating a new API key entirely.

What is YouTube API Error?

Core API errorsAccess forbidden. The request may not be properly authorized. quotaExceeded (403) quotaExceeded. The request cannot be completed because you have exceeded your quota.

How do I enable YouTube API?

After creating your project, make sure the YouTube Data API is one of the services that your application is registered to use: Go to the API Console and select the project that you just registered. Visit the Enabled APIs page. In the list of APIs, make sure the status is ON for the YouTube Data API v3.


1 Answers

You need to remove all < > characters from your description.

$description = str_replace(['>', '<'], '', $description);
$snippet->setDescription($description);
like image 199
Mowshon Avatar answered Sep 19 '22 12:09

Mowshon