E
E
Elon2021-08-23 14:08:57
Google
Elon, 2021-08-23 14:08:57

How to get a Google Auth user token?

I'm trying to implement authorization using the Google API.
When receiving a token, it gives an error, I don’t know how to fix it and I can’t find it in Google

Here is the code:

$client = new Google_Client();
$client -> setClientId(CLIENT_ID);
$client -> setRedirectUri(REDIRECT_URL);
$client -> addScope("profile");

echo "<a href=" . $client -> createAuthUrl() . ">Войти через google</a>";

if (isset($_GET['code'])) {
    $token = $client->fetchAccessTokenWithAuthCode($_GET['code']);
    $client->setAccessToken($token['access_token']);
    tt($token);

}

function tt($data){
    echo '<pre>';
    print_r($data);
    echo '</pre>';
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question