cron作业中的Google Drive API错误

Mic*_*uel 3 php ssl curl google-drive-api

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

 ?>
Run Code Online (Sandbox Code Playgroud)

我进行了身份验证并获得了刷新令牌和访问令牌,并将它们放入变量中$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
Run Code Online (Sandbox Code Playgroud)

小智 5

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

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

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