Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3712

Issue with Incomplete Video Uploads Using Google API Client 2.0 PHP Library

$
0
0

We have encountered a problem with the publishing API procedure using the "google/apiclient 2.0 PHP" library, and we kindly request your assistance in resolving this issue.

In specific cases, videos are not being fully uploaded. For example, we recently published a video with a duration of 31 minutes and 11 seconds. However, the uploaded video on YouTube is only 28 minutes long. Another user experienced a similar issue, with their video being uploaded for merely 3 to 4 minutes.

Despite these incomplete uploads, there are no publishing errors, and the post status is displayed as "published" as usual. It is important to note that a verified user can typically upload videos up to 12 hours in length.

Below is our current implementation for uploading videos using the "google/apiclient" library:

`// REPLACE this value with the path to the file you are uploading.$videoPath = "/path/to/file.mp4";

// Create a snippet with title, description, tags and category ID// Create an asset resource and set its snippet metadata and type.// This example sets the video's title, description, keyword tags, and// video category.$snippet = new Google_Service_YouTube_VideoSnippet();$snippet->setTitle("Test title");$snippet->setDescription("Test description");$snippet->setTags(array("tag1", "tag2"));// Numeric video category. See// https://developers.google.com/youtube/v3/docs/videoCategories/list$snippet->setCategoryId("22");// Set the video's status to "public". Valid statuses are "public",// "private" and "unlisted".$status = new Google_Service_YouTube_VideoStatus();$status->privacyStatus = "public";// Associate the snippet and status objects with a new video resource.$video = new Google_Service_YouTube_Video();$video->setSnippet($snippet);$video->setStatus($status);// Specify the size of each chunk of data, in bytes. Set a higher value for// reliable connection as fewer chunks lead to faster uploads. Set a lower// value for better recovery on less reliable connections.$chunkSizeBytes = 1 * 1024 * 1024;// Setting the defer flag to true tells the client to return a request which can be called// with ->execute(); instead of making the API call immediately.$client->setDefer(true);// Create a request for the API's videos.insert method to create and upload the video.$insertRequest = $youtube->videos->insert("status,snippet", $video);// Create a MediaFileUpload object for resumable uploads.$media = new Google_Http_MediaFileUpload(    $client,    $insertRequest,'video/*',    null,    true,    $chunkSizeBytes);$media->setFileSize(filesize($videoPath));// Read the media file and upload it chunk by chunk.$status = false;$handle = fopen($videoPath, "rb");while (!$status && !feof($handle)) {  $chunk = fread($handle, $chunkSizeBytes);  $status = $media->nextChunk($chunk);}fclose($handle);// If you want to make other calls after the file upload, set setDefer back to false$client->setDefer(false);`

We would greatly appreciate your help in identifying the problem and providing a solution. Your support and collaboration are invaluable to us.

Thank you, and we look forward to your response.

Our objective is to seek assistance in resolving an issue with incomplete video uploads using the "google/apiclient 2.0 PHP" library and to request help in identifying the problem and providing a solution.


Viewing all articles
Browse latest Browse all 3712

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>