gpt4 book ai didi

php - YouTube PHP API v3 - 包含recordingDetails时上传失败 - Double的值无效

转载 作者:行者123 更新时间:2023-12-03 05:24:47 24 4
gpt4 key购买 nike

我正在尝试添加 recordingDetails上传调用。它似乎在小测试文件上工作正常,但对于较大的文件,我收到以下错误:

Failed to start the resumable upload (HTTP 400: global, Invalid value for 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);
}

最佳答案

您似乎在对象上设置了“无效”值,并且根据您的详细信息,我了解到与 Google_Service_YouTube_VideoRecordingDetails 或 Google_Service_YouTube_GeoPoint 有关。我的猜测是您以错误的格式设置坐标,但这只是猜测。尝试评论此行 $recordingDetails->setLocation($locationdetails);并检查结果。我在使用谷歌驱动器时遇到过同样的问题(如果我取消注释行 createdTime 我得到 fatal error :未捕获的异常 'Google_Exception' 并带有消息'无法启动可恢复上传(HTTP 400:全局,无效值:无效格式:“1463431798”在/home/ubuntu/workspace/gdrive/vendor/google/apiclient/src/Google/Http/MediaFileUpload.php:334 中的“8”)' 格式错误

$file = new Google_Service_Drive_DriveFile();
$file->title = "repkit.tar.gz";
// $file->createdTime = time();

所以也许 Double 指的是一些预期的格式,我唯一能猜到的地方是坐标。
希望这能给你一些线索。

关于php - YouTube PHP API v3 - 包含recordingDetails时上传失败 - Double的值无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30538427/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com