[Google Client Library]Google通信のデバッグログを画面に出力する方法

GoogleAnalytics APIなど、Google Client LibraryのSDKを使用したプログラムを作る際、認証処理など、通信でエラーになる場合があります。
このような場合、デバッグログを出力させると問題の切り分けが容易になります。

以下のコードのように、Google_Config::setLoggerClass()の指定やGoogle_IO_Curlクラスのログレベル変更を行うことで、デバッグログの出力が可能となります。

// 動作のロギングクラスを指定する
$config = new \Google_Config();
$config->setLoggerClass('Google_Logger_File');
 
$client = new \Google_Client($config);
 
// cURLのログ出力をVERBOSEにする
$client->setClassConfig('Google_IO_Curl', 'options', array( CURLOPT_VERBOSE => TRUE));



上記変更を行ったうえでプログラムを実行すると、下記のようなログが出力されます。

[04/May/2016:23:14:07 +0900] DEBUG: File cache miss {
    "key": "...",
    "file": "/tmp/Google_Client/..."
}
[04/May/2016:23:14:07 +0900] DEBUG: OAuth2 access token expired
[04/May/2016:23:14:07 +0900] INFO: OAuth2 access token refresh with Signed JWT assertion grants.
[04/May/2016:23:14:07 +0900] DEBUG: cURL request {
    "url": "https://accounts.google.com/o/oauth2/token",
    "method": "POST",
    "headers": {
        "content-type": "application/x-www-form-urlencoded",
        "content-length": 761
    },
    "body": "grant_type=assertion&assertion_type=..."
}
* About to connect() to accounts.google.com port 443 (#0)
*   Trying 216.58.197.173... * connected
* Connected to accounts.google.com (216.58.197.173) port 443 (#0)
* Initializing NSS with certpath: none
* Unable to initialize NSS
* NSS error -8023
* Closing connection #0
* Problem with the SSL CA cert (path? access rights?)
[04/May/2016:23:14:07 +0900] ERROR: cURL Problem with the SSL CA cert (path? access rights?)



ログを見るとNSS error -8023と出ており、このエラーコードで調べると下記がエラーを引き起こした原因のようです。

A PKCS #11 module returned CKR_DEVICE_ERROR, 
indicating that a problem has occurred with the token or slot


関連記事

コメントを残す

メールアドレスが公開されることはありません。