Google Drive API GuzzleHttp \ Exception \ RequestException

时间:2017-02-15 20:10:58

标签: php curl oauth google-drive-api

按照以下主题的说明操作: https://github.com/google/google-api-php-client/issues/788 https://developers.google.com/api-client-library/php/guide/media_upload

我尝试解决以下问题并将文件上传到Google云端硬盘:

  

致命错误:未捕获GuzzleHttp \ Exception \ RequestException:cURL错误60:SSL证书问题,验证CA证书是否正常。详细信息:错误:14090086:SSL例程:SSL3_GET_SERVER_CERTIFICATE:证书验证失败(请参阅http://curl.haxx.se/libcurl/c/libcurl-errors.html)in /secret/public_html/v5/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php :187堆栈跟踪:#0 / secret/public_html/v5/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php(150):GuzzleHttp \ Handler \ CurlFactory :: createRejection(Object(GuzzleHttp) \ Handler \ EasyHandle),数组)#1 / secret /public_html/v5/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php(103):GuzzleHttp \ Handler \ CurlFactory :: finishError( Object(GuzzleHttp \ Handler \ CurlHandler),Object(GuzzleHttp \ Handler \ EasyHandle),Object(GuzzleHttp \ Handler \ CurlFactory))#2 / secret / public_html / v5 / vendor / guzzlehttp / guzzle / src /Handler/CurlHandler.php(43):GuzzleHttp \ Handler \ CurlFactory :: fin in /secret/public_html/v5/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php on 187 < / p>

使用PHP中的API,当文件小于5 MB时,它不会显示错误,但是,大于此的文件会产生上述错误。问题是API还是证书?即使在我的Linux服务器上安装它,错误仍然存​​在,有谁知道如何解决这个问题?或者你曾经遇到过这样的事情吗?

以下是我用来上传最多5 MB工作的代码。

<?php

$client = new Google_Client();
$client->setAuthConfig("client_secret.json");
$client->setIncludeGrantedScopes(true);
$client->setAccessType("offline");
$client->setAccessToken($access_token);

$drive_service = new Google_Service_Drive($client);

$mime_type = mime_content_type($uploadfile);

$file = new Google_Service_Drive_DriveFile();
$result = $drive_service->files->create($file, array(
    "data" => file_get_contents($uploadfile),
    "mimeType" => $mime_type,
    "uploadType" => "media"
)); 

以下是我用于上传较大的5 MB无法正常工作的代码。

<?php

$client = new Google_Client();
$client->setAuthConfig("client_secret.json");
$client->setIncludeGrantedScopes(true);
$client->setAccessType("offline");
$client->setAccessToken($access_token);

$drive_service = new Google_Service_Drive($client);

$mime_type = mime_content_type($uploadfile);

$file = new Google_Service_Drive_DriveFile();
$file->title = $uploadname;
$chunkSizeBytes = 1 * 1024 * 1024;

$client->setDefer(true);
$request = $drive_service->files->create($file); // insert

$media = new Google_Http_MediaFileUpload($client, $request, $mime_type, null, true, $chunkSizeBytes);
$media->setFileSize(filesize($uploadfile));

$status = false;
$handle = fopen($uploadfile, "rb");

while (!$status && !feof($handle)) {
    $chunk = fread($handle, $chunkSizeBytes);
    $status = $media->nextChunk($chunk);
}

$result = false;
if($status != false) {
    $result = $status;
}

fclose($handle);

$client->setDefer(false);

0 个答案:

没有答案