Authorisation Error Error 400: invalid_request saat ingin membuat API Login with Google

Screenshot 2022-06-19 063449.png

Saya mau buat pilihan "Login with Google" dengan API. Lalu setelah saya mengklik button Login dengan Akun Google" itu muncul error seperti ini


Authorisation ErrorError 400: invalid_requestInvalid parameter value for approval_prompt: 'auto'' is not valid

. Gimana ya benerinnya?

Ini kodenya

<?php

require_once 'vendor/autoload.php';
$clientID='340784022267-s1h4l6gsabreff04ms37bbi53ie3iuno.apps.googleusercontent.com';

$clientSecret='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';

$redirectUrl = "http://localhost/glogin/login.php";

// membuat client request ke google

$client = new Google_Client();

$client->setClientId($clientID);

$client->setClientSecret($clientSecret);

$client->setRedirectUri($redirectUrl);

$client->addScope('profile');

$client->addScope('email');

if(isset($_GET['code'])){
$token=$client->fetchAccessTokenWithAuthCode($_GET['code']);
$client->setAccessToken($token);
    //Mendapatkan user profile
$gauth = new Google_Service_Oauth2($client);
$google_info = $gauth->userinfo->get();
$email = $google_info->email;
$name = $google_info->name;
    echo "Selamat Datang " .$name. " Anda telah terdaftar menggunakan email : " .$email;} else{
echo "<a href=".$client->createAuthUrl()."'>Login dengan akun Google</a>";
}

berikut link video tutorial yang saya ikuti https://www.youtube.com/watch?v=i5IybpgcInY&t=1s

avatar karu
@karu

3 Kontribusi 0 Poin

Diperbarui 1 tahun yang lalu

1 Jawaban:

<div>coba dengan menambahkan</div><pre>$client-&gt;setPrompt('consent');</pre><div><br>Informasi<br><a href="https://developers.google.com/identity/protocols/oauth2/openid-connect#authenticationuriparameters">https://developers.google.com/identity/protocols/oauth2/openid-connect#authenticationuriparameters</a></div>

avatar hilmanski
@hilmanski

2670 Kontribusi 2132 Poin

Dipost 1 tahun yang lalu

Login untuk ikut Jawaban