相关疑难解决方法(0)

首次登录和授权后,Google+ OAuth API会存储和检索令牌

我已经阅读了有关如何使用Google API的文档,示例和教程,我已经运行了一个显示您最新活动和信息的迷你应用程序,但我使用会话来存储令牌.

我的问题是,如何从数据库中存储和检索令牌,以便当用户(已经注册)点击"登录"时,它可以立即使用API​​而无需重复授权?请注意,我使用该示例作为我的迷你应用程序的起点.

这是一段代码片段:

$client = new apiClient();
$client->setApplicationName(APP_NAME);
$client->setClientId(CLIENT_ID);
$client->setClientSecret(CLIENT_SECRET);
$client->setRedirectUri(REDIRECT_URL);
$client->setDeveloperKey(DEV_KEY);

$plus = new apiPlusService($client);
$google_userinfo = new apiOauth2Service($client);

$message = "";

// In a real application this would be stored in a database, and not in the session!
if (isset($_SESSION['token']))
  $client->setAccessToken($_SESSION['token']);

$_SESSION['token'] = $client->getAccessToken();

if (isset($_GET['code'])) {
   $client->authenticate();
  // In a real application this would be stored in a database, and not in the session!
  $_SESSION['token'] = $client->getAccessToken();
  header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
}
...
 //Somewhere …
Run Code Online (Sandbox Code Playgroud)

oauth-2.0 google-plus

5
推荐指数
1
解决办法
5289
查看次数

标签 统计

google-plus ×1

oauth-2.0 ×1