YouTube PHP API v3 - Upload Fails when including recordingDetails - Invalid value for Double -
i'm trying add recordingdetails
upload call. seems work fine on small test files, larger files i'm getting following error:
failed start resumable upload (http 400: global, invalid value double: )
with of debugging code able find out error happens when executing line of code: $status = $media->nextchunk($chunk);
if comment out $video->setrecordingdetails($recordingdetails);
same file uploads fine.
i'm new api, , can't seem find related error online. guidance or suggestions appreciated!
my code below:
# file info 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 snippet title, description, tags , category id // create asset resource , set snippet metadata , type. // example sets video's title, description, keyword tags, , // 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 video's status "public". valid statuses "public", // "private" , "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 snippet , status objects new video resource. $video = new google_service_youtube_video(); $video->setsnippet($snippet); $video->setstatus($status); $video->setrecordingdetails($recordingdetails); // specify size of each chunk of data, in bytes. set higher value // reliable connection fewer chunks lead faster uploads. set lower // value better recovery on less reliable connections. if(!is_numeric($youtube_chunk_size)){$youtube_chunk_size=10;} $chunksizebytes = intval($youtube_chunk_size) * 1024 * 1024; // setting defer flag true tells client return request can called // ->execute(); instead of making api call immediately. $client->setdefer(true); // create request api's videos.insert method create , upload video. $insertrequest = $youtube->videos->insert("status,snippet,recordingdetails", $video); // create mediafileupload object resumable uploads. $media = new google_http_mediafileupload( $client, $insertrequest, 'video/*', null, true, $chunksizebytes ); $media->setfilesize(filesize($videopath)); // read media file , upload chunk chunk. $status = false; $handle = fopen($videopath, "rb"); while (!$status && !feof($handle)) { $chunk = fread($handle, $chunksizebytes); $status = $media->nextchunk($chunk); } fclose($handle); // if want make other calls after file upload, set setdefer 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); }
it seems set "invalid" value on object , details understand related google_service_youtube_videorecordingdetails or google_service_youtube_geopoint. guess setting coordinates in wrong format guess. try comment line $recordingdetails->setlocation($locationdetails);
, check result. i've experienced same kind of problem google drive (if uncomment line createdtime fatal error: uncaught exception 'google_exception' message 'failed start resumable upload (http 400: global, invalid value for: invalid format: "1463431798" malformed @ "8")' in /home/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();
so maybe double referring expected format , place can guess coordinates. hope give clue.
Comments
Post a Comment