Php 无法启动可恢复上载(HTTP 404)

Php 无法启动可恢复上载(HTTP 404),php,youtube,google-client-login,Php,Youtube,Google Client Login,这是我的代码,我花了几个小时来解决这个问题,唯一的错误是:无法启动可恢复上传(HTTP 404) 有没有办法看到更多的错误细节,或者你们知道是什么导致了这个错误?我已经授予了访问权限和一切,我也检查了过期的代币,但无法上传视频b/c 请至少提示一下如何查看更多错误详细信息。 try{ // REPLACE this value with the path to the file you are uploading.

这是我的代码,我花了几个小时来解决这个问题,唯一的错误是:无法启动可恢复上传(HTTP 404)

有没有办法看到更多的错误细节,或者你们知道是什么导致了这个错误?我已经授予了访问权限和一切,我也检查了过期的代币,但无法上传视频b/c

请至少提示一下如何查看更多错误详细信息。

                try{
                    // REPLACE this value with the path to the file you are uploading.
                    $videoPath = $_FILES['video']['tmp_name'];

                    // 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($_POST['title']);
                    $snippet->setDescription($this->input->post('description'));
                    $snippet->setTags(array("tag1", "tag2"));

                    // Numeric video category. See
                    // https://developers.google.com/youtube/v3/docs/videoCategories/list
                    $snippet->setCategoryId("22");

                    // Set the video's status to "public". Valid statuses are "public",
                    // "private" and "unlisted".
                    $status = new Google_Service_YouTube_VideoStatus();
                    $status->privacyStatus = "unlisted";

                    // Associate the snippet and status objects with a new video resource.
                    $video = new Google_Service_YouTube_Video();
                    $video->setSnippet($snippet);
                    $video->setStatus($status);

                    // 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.
                    $chunkSizeBytes = 1 * 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.
                    $this->client->setDefer(true);

                    $finfo = finfo_open(FILEINFO_MIME_TYPE);
                    $ext= finfo_file($finfo, $_FILES['video']['tmp_name']);

                    // Create a request for the API's videos.insert method to create and upload the video.
                    $insertRequest = $this->youtube->videos->insert("status,snippet", $video,
                                     array("data"=>file_get_contents($_FILES['video']['tmp_name']),
                                           "uploadType" => "media",
                                           "mimeType" => 'application/octet-stream'));

                    // Create a MediaFileUpload object for resumable uploads.
                    $media = new Google_Http_MediaFileUpload(
                        $this->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
                    $this->client->setDefer(false);
                    $videoID = $status['id'];

                } catch (Google_ServiceException $e) {
                        $response['success'] = 'Failed to upload video, contact support! a Message:'.$e->getMessage();
                        return $this->output
                        ->set_content_type('application/json')
                        ->set_output(json_encode($response));
                } catch (Google_Exception $e) {
                        $response['success'] = 'Failed to upload video, contact support! b Message:'.$e->getMessage();
                        return $this->output
                        ->set_content_type('application/json')
                        ->set_output(json_encode($response));
                }
//乐


您应该检查
php
错误日志

  • 在Linux环境中,它应该位于:
    var/log/httpd/error\u log

  • 在Windows环境中,您应该检查
    php.ini

error\u log=c:/server/php.log
行查找位置

编辑:如果未启用错误,请在
php.ini中更改以下行

log\u errors=On

并重现错误


EDIT2:如果您还没有看过,下面的示例似乎也很多。

ClientLogin for Google已经关闭:

我最近不得不在一个应用程序上重新编码身份验证来解决这个问题。您现在必须使用OAuth向Google进行身份验证。好消息是:有很多代码可以帮助您,包括在Google上:

                try{
                    // REPLACE this value with the path to the file you are uploading.
                    $videoPath = $_FILES['video']['tmp_name'];

                    // 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($_POST['title']);
                    $snippet->setDescription($this->input->post('description'));
                    $snippet->setTags(array("tag1", "tag2"));

                    // Numeric video category. See
                    // https://developers.google.com/youtube/v3/docs/videoCategories/list
                    $snippet->setCategoryId("22");

                    // Set the video's status to "public". Valid statuses are "public",
                    // "private" and "unlisted".
                    $status = new Google_Service_YouTube_VideoStatus();
                    $status->privacyStatus = "unlisted";

                    // Associate the snippet and status objects with a new video resource.
                    $video = new Google_Service_YouTube_Video();
                    $video->setSnippet($snippet);
                    $video->setStatus($status);

                    // 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.
                    $chunkSizeBytes = 1 * 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.
                    $this->client->setDefer(true);

                    $finfo = finfo_open(FILEINFO_MIME_TYPE);
                    $ext= finfo_file($finfo, $_FILES['video']['tmp_name']);

                    // Create a request for the API's videos.insert method to create and upload the video.
                    $insertRequest = $this->youtube->videos->insert("status,snippet", $video,
                                     array("data"=>file_get_contents($_FILES['video']['tmp_name']),
                                           "uploadType" => "media",
                                           "mimeType" => 'application/octet-stream'));

                    // Create a MediaFileUpload object for resumable uploads.
                    $media = new Google_Http_MediaFileUpload(
                        $this->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
                    $this->client->setDefer(false);
                    $videoID = $status['id'];

                } catch (Google_ServiceException $e) {
                        $response['success'] = 'Failed to upload video, contact support! a Message:'.$e->getMessage();
                        return $this->output
                        ->set_content_type('application/json')
                        ->set_output(json_encode($response));
                } catch (Google_Exception $e) {
                        $response['success'] = 'Failed to upload video, contact support! b Message:'.$e->getMessage();
                        return $this->output
                        ->set_content_type('application/json')
                        ->set_output(json_encode($response));
                }
 ! ) Fatal error: Uncaught exception 'Google_Exception' with message 'Failed to start the resumable upload (HTTP 404)' in /home/user/app/vendor/google/apiclient/src/Google/Http/MediaFileUpload.php on line 299
( ! ) Google_Exception: Failed to start the resumable upload (HTTP 404) in /home/user/app/vendor/google/apiclient/src/Google/Http/MediaFileUpload.php on line 299
Call Stack
#   Time    Memory  Function    Location
1   0.0004  285400  {main}( )   .../index.php:0
2   0.0162  1112448 require_once( '/home/user/app/system/core/CodeIgniter.php' )    .../index.php:210
3   0.0633  4532576 call_user_func_array:{/home/mio/zsuite-dev/system/core/CodeIgniter.php:359} ( ) .../CodeIgniter.php:359
4   0.0634  4534256 Presentation->index( )  .../CodeIgniter.php:359
5   0.4291  8672016 Presentation->_save_update_presentation( )  .../presentation.php:155
6   0.4952  9206376 Google_Http_MediaFileUpload->nextChunk( )   .../presentation.php:289
7   0.4952  9206736 Google_Http_MediaFileUpload->getResumeUri( )    .../MediaFileUpload.php:138