2017-10-19 32 views
-1

phpのバージョン2.2.0でgoogle apiを使用してGoogleカレンダーに接続しようとしています。これまで私はカレンダーに接続することに成功せず、非常にイライラしています。私は、次の致命的なエラーを受け取る。この時点ではJsonキーにタイプフィールドがありません

:私は、トークンが生成されていることがわかり

require_once WP_PLUGIN_DIR . '/google-api-php-client-2.2.0/vendor/autoload.php'; 
require_once WP_PLUGIN_DIR . '/google-api-php-client-2.2.0/src/Google/Client.php'; 
require_once WP_PLUGIN_DIR . "/google-api-php-client-2.2.0/vendor/google/apiclient-services/src/Google/Service/Calendar/Resource/CalendarList.php"; 
require_once WP_PLUGIN_DIR . "/google-api-php-client-2.2.0/vendor/google/apiclient-services/src/Google/Service/Oauth2.php"; 


putenv('GOOGLE_APPLICATION_CREDENTIALS=' . dirname(__FILE__) . '/oauth-credentials.json'); 

$client = new Google_Client(); 
$redirect_uri = 'https://myredirect-uri'; 
$client->setRedirectUri($redirect_uri); 

$client->setRedirectUri($redirect_uri); 
$client->setClientId('myclient-di.apps.googleusercontent.com'); 
$client->setClientSecret('myclient-secret'); 
$client->setAccessType("offline");  // offline access 
$client->setIncludeGrantedScopes(true); // incremental auth 
$client->addScope(Google_Service_Calendar::CALENDAR); 

$user_to_impersonate = '[email protected]'; 
$client->setSubject($user_to_impersonate); 
$client->setAuthConfig(GOOGLE_APPLICATION_CREDENTIALS); 

$client->useApplicationDefaultCredentials(); 

if (file_exists(CREDENTIALS_PATH)) { 
    $token = file_get_contents(CREDENTIALS_PATH); 
    echo "<h4>_Token</h4>"; 
    var_dump($token); 
    $client->setAccessToken($token); 
} 
echo "<br><br>CLIENT"; 

$service = new Google_Service_Calendar($client); 

$calendarList = $service->calendarList->listCalendarList(); 
var_dump($calendarList); 

echo "<h4>End of example</h4>"; 

Fatal error: Uncaught InvalidArgumentException: json key is missing the type field in /home/servi471/public_html/wp-content/plugins/google-api-php-client-2.2.0/vendor/google/auth/src/CredentialsLoader.php:123 Stack trace: #0 /home/servi471/public_html/wp-content/plugins/google-api-php-client-2.2.0/vendor/google/auth/src/ApplicationDefaultCredentials.php(154): Google\Auth\CredentialsLoader::makeCredentials(' https://www.goo ...', Array) #1 /home/servi471/public_html/wp-content/plugins/google-api-php-client-2.2.0/src/Google/Client.php(1078): Google\Auth\ApplicationDefaultCredentials::getCredentials(' https://www.goo ...')

2 /home/servi471/public_html/wp-content/plugins/google-api-php-client-2.2.0/src/Google/Client.php(365):

Google_Client->createApplicationDefaultCredentials() #3 /home/servi471/public_html/wp-content/plugins/google-api-php-client-2.2.0/src/Google/Client.php(786): Google_Client->authorize() #4 /home/servi471/public_html/wp-content/plugins/google-api-php-client-2.2.0/src/Google/Service/Resource.php(232): Google_C in /home/servi471/public_html/wp-content/plugins/google-api-php-client-2.2.0/vendor/google/auth/src/CredentialsLoader.php on line 123

私はこのコードを使用します。

誰かがこの接続を手助けしてくれますか?

+0

は '/ OAuthの-credentials.json'は' type'がフィールドが欠落している中、JSONブロブのように私には見えます。あなたはそのファイルの内容を含めていないので、デバッグは難しいですが、私はそれをGoogleが見つけようとしているものと比較することから始めます。 –

+0

ファイルの内容はGoogleのものですから、大丈夫だと思います。私は設定が大丈夫ではありません..... pffftt –

+0

申し訳ありません、ファイルの内容: {"web":{"client_id": "my-client-id"、 "project_id": "my -project-id "、" auth_uri ":" https://accounts.google.com/o/oauth2/auth "、" token_uri ":" https://accounts.google.com/o/oauth2/token "、 "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs"、 "client_secret": "my-client-secret"、 "redirect_uris":["https:// my-redirect-uri" ]、 "javascript_origins":["https://my-website.nl"]}} –

答えて

0

JSON-key-fileにtypeフィールドが含まれていませんでした。しかし、いくつかのステートメントを削除し、最小限のデータに戻しました。また、ステートメントを追加しました:

$client->setApprovalPrompt('force');

関連する問題