1 year ago
#376163
Jonus1993
Google api client "Malformed auth code" in Laravel PHP Merchant project
I got a problem with a using the google/apiclient package. When I trying to get an access_token using auth code from front-end I getting back error form google "Malformed auth code".
The google auth code looks like this one:
ya29.A0ARrdaM8wqLBvw5yrNa0wDQGPSUvncigERIqtYC_D2tQl2QCYm3rbcthI_om_BcHGFGcDrN6qgUM37zt9ot7OsgEth5XZzZe__ed5B4artd9QNRRK0WD0wnaDl3kjxPKEcp9o53lbloypz7t7KoxO5Mg2PH0
Thats my code:
/**
* @return Google\Client
* @throws Google\Exception
*/
public static function getClientHeaders()
{
$client = new Google\Client();
$client->setApplicationName(config('services.google.app_name'));
$client->setAuthConfig(config('merchant.config_file'));
$client->setScopes('https://www.googleapis.com/auth/content');
return $client;
}
/**
* @param string $token
* @return Google\Client
* @throws Google\Exception
*/
public static function getClient(string $token)
{
$client = static::getClientHeaders();
if ($client->isAccessTokenExpired()) {
if ($client->getRefreshToken()) {
$client->fetchAccessTokenWithRefreshToken($client->getRefreshToken());
} else {
$creds = $client->fetchAccessTokenWithAuthCode($token);
if (isset($creds['error'])) {
abort(Response::HTTP_BAD_REQUEST, $creds['error_description']);
}
}
}
return $client;
}
public function getToken()
{
$client = static::getClient(request()->input('access_token'));
$token = $client->getAccessToken();
}
I am getting an error when I try to run getToken() function. Maybe You can see what am I doing wrong :(
php
laravel
google-api-php-client
google-api-client
0 Answers
Your Answer