我在 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