Код: Выделить всё
$client = new \Google_Client();
//this loads a file containing the keys
$client->setAuthConfig(realpath('google.json'));
//verify token and get user info from payload
$payload = $client->verifyIdToken($token);
if($payload){
//user is logged, $payload->sub is user_id
//both token and user_id are saved in user document for later use
}
< /code>
В другом сценарии, позже, я пытаюсь использовать службу в качестве моего регистрированного пользователя, повторно используя токен, который был получен в качестве входа в систему, выполняя < /p>
$client = new \Google_Client();
//this loads a file containing the keys
$client->setAuthConfig(realpath('google.json'));
//set the user token to the client
$client->setSubject($user_email);
$client->addScope('https://www.googleapis.com/auth/business.manage');
$client->setAccessToken($token);
//list accounts
$service = new \Google_Service_MyBusinessAccountManagement($client);
$accounts = $service->accounts->listAccounts()->getAccounts();
< /code>
Я получаю ошибку, которую клиент неавторизован < /p>
PHP Fatal error: Uncaught Google\Service\Exception: { "error": "unauthorized_client", "error_description": "Client is unauthorized to retrieve access tokens using this method, or client not authorized for any of the scopes requested." }
Подробнее здесь: https://stackoverflow.com/questions/796 ... fter-login