YouTube PHP API v3-包含recordingDetails时上载失败-双精度的值无效

YouTube PHP API v3-包含recordingDetails时上载失败-双精度的值无效,php,youtube,Php,Youtube,我正在尝试将recordingDetails添加到上传呼叫。对于小的测试文件,它似乎工作得很好,但对于较大的文件,我会遇到以下错误: 无法启动可恢复上载(HTTP 400:全局,双精度的值无效:) 在一些调试代码的帮助下,我在执行这行代码时发现了这个错误:$status=$media->nextChunk($chunk) 如果我注释掉$video->setRecordingDetails($recordingDetails)相同的文件可以上传 我是API新手,在网上似乎找不到与此错误相关的任何内

我正在尝试将
recordingDetails
添加到上传呼叫。对于小的测试文件,它似乎工作得很好,但对于较大的文件,我会遇到以下错误:

无法启动可恢复上载(HTTP 400:全局,双精度的值无效:)

在一些调试代码的帮助下,我在执行这行代码时发现了这个错误:
$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\u服务\u YouTube\u视频录制详细信息或Google\u服务\u YouTube\u GeoPoint有关。我的猜测是,您设置的坐标格式错误,但这只是一个猜测。尝试注释此行
$recordingDetails->setLocation($locationdetails)并检查结果。我在google drive上也遇到过类似的问题(如果我用createdTime取消注释行,我会得到致命错误:未捕获异常“google_exception”,消息为“无法启动可恢复上载”(HTTP 400:global,无效值:无效格式:“146331798”在“8”处格式错误)'在/home/ubuntu/workspace/gdrive/vendor/google/apiclient/src/google/Http/MediaFileUpload.php:334

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

不错的问题,但尽量包含代码的相关部分,并格式化你的帖子。您可以使用反勾号或将代码缩进四个空格来使用代码(或者选择要缩进的代码并按ctrl+k)。更多信息。谢谢你的建议。我的问题发布已经快一年了。我能让它工作。回顾代码,我确实对潜在的空值进行了更多的检查。我猜我试图在
$locationdetails
中包含空值。
$file = new Google_Service_Drive_DriveFile();
  $file->title = "repkit.tar.gz";
  // $file->createdTime = time();