Googleドライブに接続してウェブサイトのファイルとデータベースをGoogleドライブアカウントに定期的にバックアップする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