我正在尝试将recordingDetails
添加到上传呼叫中。它似乎在小型测试文件上运行良好,但对于较大的文件,我收到以下错误:
无法启动可恢复上传(HTTP 400:全局,Double的无效值)
在一些调试代码的帮助下,我能够发现在执行这行代码时发生了这个错误:$status = $media->nextChunk($chunk);
如果我发表评论$video->setRecordingDetails($recordingDetails);
,则上传的内容相同。
我是API的新手,我似乎无法在线找到与此错误相关的任何内容。任何指导或建议将不胜感激!
我的代码如下:
# Get file info for upload
$resource=get_resource_data($ref);
$alternative=-1;
$ext=$resource["file_extension"];
$videoPath=get_resource_path($ref,true,"",false,$ext,-1,1,false,"",$alternative);
// 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($video_title);
$snippet->setDescription($video_description);
$snippet->setTags(array($video_keywords));
$snippet->setCategoryId($video_category);
// Set the video's status to "public". Valid statuses are "public",
// "private" and "unlisted".
$status = new Google_Service_YouTube_VideoStatus();
$status->privacyStatus = $video_status;
$status->setLicense($video_publish_license);
$status->setPublicStatsViewable($video_public_stats_viewable);
//
$recordingDetails=new Google_Service_YouTube_VideoRecordingDetails();
$locationdetails=new Google_Service_YouTube_GeoPoint();
$locationdetails->setLatitude($resource['geo_lat']);
$locationdetails->setLongitude($resource['geo_long']);
$recordingDetails->setLocation($locationdetails);
// Associate the snippet and status objects with a new video resource.
$video = new Google_Service_YouTube_Video();
$video->setSnippet($snippet);
$video->setStatus($status);
$video->setRecordingDetails($recordingDetails);
// 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.
if(!is_numeric($youtube_chunk_size)){$youtube_chunk_size=10;}
$chunkSizeBytes = intval($youtube_chunk_size) * 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,recordingDetails", $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(true);
$youtube_new_url = "https://www.youtube.com/watch?v=" . $status['id'];
return array(true,$youtube_new_url);
}
catch (Google_ServiceException $e)
{
$errortext= sprintf('<p>A service error occurred: <code>%s</code></p>',
htmlspecialchars($e->getMessage()));
}
catch (Google_Exception $e)
{
$errortext= sprintf('<p>An client error occurred: <code>%s</code></p>',
htmlspecialchars($e->getMessage()));
}
catch (Google_ServiceException $e)
{
$errortext = sprintf('<p>A service error occurred: <code>%s</code></p>',
htmlspecialchars($e->getMessage()));
}
catch (Google_Exception $e)
{
$errortext = sprintf('<p>A client error occurred: <code>%s</code></p>',
htmlspecialchars($e->getMessage()));
}
if(isset($errortext))
{
return array(false,$errortext);
}
答案 0 :(得分:0)
您似乎在对象上设置了“无效”值,并且根据您的详细信息,我了解该信息与Google_Service_YouTube_VideoRecordingDetails或Google_Service_YouTube_GeoPoint相关。我的猜测是你以错误的格式设置坐标,但这只是猜测。尝试对此行$recordingDetails->setLocation($locationdetails);
发表评论并检查结果。我在谷歌驱动器上遇到了同样的问题(如果我使用createdTime取消注释,我会得到 致命错误:未捕获的异常'Google_Exception',并显示消息'无法启动可恢复的上传(HTTP 400:全局,无效)值:格式无效:“1463431798”格式错误为“8”)/ inhome/ubuntu/workspace/gdrive/vendor/google/apiclient/src/Google/Http/MediaFileUpload.php:334强>)
$file = new Google_Service_Drive_DriveFile();
$file->title = "repkit.tar.gz";
// $file->createdTime = time();
所以也许Double指的是一些预期的格式,我唯一可以猜到的是坐标。 希望这能给你一些线索。