跟随google-api-php-client => documentation我设法获得$token = $client->fetchAccessTokenWithAuthCode($authorization_code);
数组:
$token array:6 [▼ ▼
"access_token" => "***"
"expires_in" => 3599
"refresh_token" => "***"
"scope" => "https://www.googleapis.com/auth/drive openid https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile"
"token_type" => "Bearer"
"id_token" => "***"
]
我使用了$client->setAccessType("offline");
,所以我得到了"refresh_token" => "***"
文档提及:
,我需要这样做:如果您使用Google API客户端库,则只要您将该对象配置为脱机访问,客户端对象就会根据需要刷新访问令牌。
我了解要访问Google API 无需用户交互
$client = new Google_Client(); $client->setAccessToken($token);
$token
是上面的数组。然后我可以进行api调用。
1)我应该如何存储此$token
数组?我是否只需要存储refresh_token
?如果是这样,如何重建$token
数组,以便setAccessToken()
方法可以接受它?
2)我应该在哪里存储数组数据?在数据库中还是其他地方?
按照google-api-php-client =>文档,我设法获得了$ token = $ client-> fetchAccessTokenWithAuthCode($ authorization_code);数组:$ token数组:6 [▼▼“ access_token” =>“ ***” ...
您实际上只需要存储刷新令牌。它的存储位置由您自己决定,但是它应该在某个地方安全,并且应该指示刷新令牌附加到的用户。这样可以确保您不会向用户显示用户b数据,因为您混淆了他们的刷新令牌。