3

我在 cpanel 中有一个 cron 作业,它连接到谷歌驱动器以定期将网站文件和数据库备份到谷歌驱动器帐户。我简化了文件以发现问题:

<?php

set_time_limit(0);

require_once 'google-api-php-client/Google_Client.php';
require_once 'google-api-php-client/contrib/Google_DriveService.php';

$client = new Google_Client();
$client>setClientId('xxxx');
$client->setClientSecret('xxxx');
$service = new Google_DriveService($client);

$accessToken = '{ "access_token" : "xxx", "token_type" : "Bearer", "expires_in" : 3600, 
"refresh_token" : "1/xxx" }';
$client->setAccessToken($accessToken);

$files = $service->files->listFiles();

print($files);

 ?>

我进行了身份验证并获得了刷新令牌和访问令牌并将它们放入变量中$accessToken。该脚本在从浏览器运行时有效,但是当我将其设置为 cron 作业时,我收到以下错误:

[13-Jul-2013 13:41:02 Europe/Moscow] PHP Fatal error:  Uncaught exception 
'Google_IOException' with message 'HTTP Error: (0) error setting certificate verify     
locations:
CAfile: /etc/pki/tls/certs/ca-bundle.crt
CApath: none
' in /home/xxxxxx/backup/google-api-php-client/io/Google_CurlIO.php:128
Stack trace:
#0 /home/xxxxxx/backup/google-api-php-client/auth/Google_OAuth2.php(270):    
Google_CurlIO->makeRequest(Object(Google_HttpRequest))
#1 /home/xxxxxx/backup/google-api-php-client/auth/Google_OAuth2.php(248): 
Google_OAuth2->refreshTokenRequest(Array)
#2 /home/xxxxxx/backup/google-api-php-client/Google_Client.php(315): 
Google_OAuth2->refreshToken('1/xxxxxx...')
#3 /home/xxxxxx/backup/index.php(20): Google_Client-   
>refreshToken('1/xxxxxx...')
#4 {main}
thrown in /home/xxxxxx/backup/google-api-php-client/io/Google_CurlIO.php on line   
128
4

3 回答 3

5

我遇到了同样的问题并更改了权限,但仍然无法使其正常工作。然后我找到了这个解决方案

在 'google-api-php-client\src\io\' 文件夹中,打开 'apiCurlIO.php' 替换 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); 与 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

在这个链接上,它对我有用。

于 2014-01-16T09:47:41.660 回答
1

cUrl 无法将证书写入其目的地。

$ chmod 755 /etc/pki/tls/certs

或者为您使用的具有写入权限的证书明确设置新目标。

于 2013-07-16T07:47:01.083 回答
0

在长时间运行的 Google Drive API 作业中,我还看到脚本因此错误而崩溃,因为它们无法打开新文件。

于 2015-04-21T05:44:05.147 回答