J'essaie de me connecter à mon agenda Google en utilisant l'API google pour php, version 2.2.0. Jusqu'à maintenant je n'arrive pas à me connecter à mon calendrier et c'est très frustrant.La clé Json ne contient pas le champ de type
En ce moment, je reçois l'erreur fatale suivante:
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
J'utilise ce code:
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>";
Je vois qu'un jeton est généré.
Quelqu'un pourrait-il m'aider s'il vous plaît à faire cette connexion?
Me semble le blob JSON dans '/ oauth-credentials.json' manque un' type' champ. Puisque vous n'avez pas inclus le contenu de ce fichier, il est difficile de le déboguer, mais je commencerais par comparer cela à ce que Google s'attend à trouver dans ce contenu. –
Le contenu du fichier provient directement de google, donc je pense que ça devrait aller. Pourrait être que je n'ai pas configuré les paramètres pas d'accord ..... pffftt –
Désolé, le contenu du fichier: {"web": {"client_id": "mon-client-id", "project_id": "mon -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": "mon-secret-client", "redirect_uris": ["https: // my-redirect-uri" ], "javascript_origins": ["https://my-website.nl"]}} –