集成HWIOAuthBundle和Google Api客户端 - 如何设置正确的令牌

时间:2014-12-09 14:18:42

标签: symfony google-api-php-client hwioauthbundle

我有symfony2页面,我使用与FOSUserBundle集成的HWIOAuthBundle。 HWIOAuth使用我自己的用户提供程序,它扩展到基本FOSUBUserProvider(HWI \ Bundle \ OAuthBundle \ Security \ Core \ User \ FOSUBUserProvider)。通过这个类,我可以检索有关AccessToken的信息。我的问题是 - 如何在Google Api客户端中设置正确的访问令牌,示例代码:

$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());

最后一行抛出错误"无法json解码令牌",当我试图设置json_encode然后它抛出"无效的令牌格式"错误

1 个答案:

答案 0 :(得分:0)

如果您使用的是Google PHP SDK的v2,则应执行以下操作

Ө(log(n))

此致