1
votes

I have symfony2 page where i use HWIOAuthBundle integrated with FOSUserBundle. HWIOAuth using my own user provider which extend through base FOSUBUserProvider (HWI\Bundle\OAuthBundle\Security\Core\User\FOSUBUserProvider). With this class i am able to retrieve information about AccessToken. My question is - how to set correct access token in Google Api Client, example code:

$client = new \Google_Client();
$client->setApplicationName("XXX");
$client->setClientId($this->container->getParameter('google_client_id'));
$client->setClientSecret($this->container->getParameter('google_client_secret'));

var_dump($user->getGoogleAccessToken()); // 83 characters string with google access token

$client->setAccessToken($user->getGoogleAccessToken());

Last line throws error "Could not json decode the token", when i trying to set json_encode then it throws "Invalid token format" error

1
Ok, nevermind. $client->setAccessToken(json_encode(['access_token' => $user->getGoogleAccessToken()])); does the work - elmasterlow
I always get token expire error, Do you have same problem ? - GirginSoft
I do not have access to site already. I don't know, sorry. - elmasterlow

1 Answers

0
votes

If you are using the v2 of Google PHP SDK, you should do the following

$client->setAccessToken([
    'access_token' => $accessToken,
    'expires_in'   => $expiresIn,
]);

Regards