YouTube PHP API v3 -上传失败时,包括recordingDetails -无效值为Double


YouTube PHP API v3 - Upload Fails when including recordingDetails - Invalid value for Double

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

启动可恢复上传失败(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我得到致命错误:未捕获的异常'Google_Exception'与消息'未能启动可恢复上传(HTTP 400:全局,无效值:无效格式:"1463431798"在"8"处格式错误)'在/home/ubuntu/workspace/gdrive/供应商/google/apiclient/src/google/HTTP/mediafileupload .php:334)

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

所以也许Double是指一些预期的格式,我唯一能猜到的地方是坐标。