Hallo,
zur Nutzung einer Google-API soll ich gemäß Anleitung wie folgt vorgehen:
- Open a terminal and run the following
curl
command:
curl -L -X POST 'https://www.googleapis.com/oauth2/v4/token?client_id=oauth2-client-id&client_secret=oauth2-client-secret&code=authorization-code&grant_type=authorization_code&redirect_uri=https://www.google.com'
- Google OAuth returns two tokens, an access token and a refresh token
Entsprechend habe ich ein Skript angelegt wie folgt (die notwendigen Angaben habe ich natürlich in der URL ergänzt…):
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.googleapis.com/oauth2/v4/token?client_id=oauth2-client-id&client_secret=oauth2-client-secret&code=authorization-code&grant_type=authorization_code&redirect_uri=https://www.google.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
Zurückbekommen habe ich nichts. Aufgrund dieses Themas habe ich das Skript wie folgt ergänzt:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.googleapis.com/oauth2/v4/token?client_id=293754290671-mmrg6tnb71nbjrrotesjvqgtii9ja0tf.apps.googleusercontent.com&client_secret=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&code=4/0AX4XfWiZUani9w2n3Z1QM0044r6x3ldLxSRg0tzr-gKwD0MWgYA8UDe0Qsi5zx3zziSfQw&grant_type=authorization_code&redirect_uri=https://www.google.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
echo $result;
curl_close ($ch);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
Immerhin hat es jetzt eine Rückmeldung gegeben, allerdings eine Fehlermeldung wie folgt:
{
„error“: „invalid_grant“,
„error_description“: „Bad Request“
}
Warning: curl_setopt(): supplied resource is not a valid cURL handle resource in /var/lib/symcon/scripts/12345.ips.php on line 18
Kann mir jemand weiterhelfen, wie ich an die Rückmeldung mit den beiden Tokens komme?
Danke und viele Grüße…