當前位置: 首頁>>代碼示例>>PHP>>正文


PHP apiClient::refreshToken方法代碼示例

本文整理匯總了PHP中apiClient::refreshToken方法的典型用法代碼示例。如果您正苦於以下問題:PHP apiClient::refreshToken方法的具體用法?PHP apiClient::refreshToken怎麽用?PHP apiClient::refreshToken使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在apiClient的用法示例。


在下文中一共展示了apiClient::refreshToken方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: refresh_access_token

 public function refresh_access_token($email = '')
 {
     if ($email == '') {
         return '';
     }
     $query = $this->db->query("SELECT refresh_token FROM " . TABLE_GOOGLE . " WHERE email=?", array($email));
     if (!isset($query->row['refresh_token'])) {
         return '';
     }
     $client = new apiClient();
     $client->setApplicationName(GOOGLE_APPLICATION_NAME);
     $client->setClientId(GOOGLE_CLIENT_ID);
     $client->setClientSecret(GOOGLE_CLIENT_SECRET);
     $client->setRedirectUri(GOOGLE_REDIRECT_URL);
     $client->setDeveloperKey(GOOGLE_DEVELOPER_KEY);
     $client->refreshToken($query->row['refresh_token']);
     $s = $client->getAccessToken();
     $a = json_decode($s);
     if (isset($a->{'access_token'})) {
         return $a->{'access_token'};
     }
     return '';
 }
開發者ID:buxiaoyang,項目名稱:EmailArchive,代碼行數:23,代碼來源:google.php

示例2: header

if (isset($_GET['code'])) {
    $client->authenticate();
    $_SESSION['access_token'] = $client->getAccessToken();
    header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
}
if (isset($_SESSION['access_token'])) {
    $client->setAccessToken($_SESSION['access_token']);
    //json decode the session token and save it in a variable as object
    $sessionToken = json_decode($_SESSION['access_token']);
    //Save the refresh token (object->refresh_token) into a cookie called 'token' and make last for 1 month
    if (isset($sessionToken->refresh_token)) {
        //refresh token is only set after a proper authorisation
        $number_of_days = 30;
        $date_of_expiry = time() + 60 * 60 * 24 * $number_of_days;
        setcookie('token', $sessionToken->refresh_token, $date_of_expiry);
    }
} else {
    if (isset($_COOKIE["token"])) {
        //if we don't have a session we will grab it from the cookie
        $client->refreshToken($_COOKIE["token"]);
        //update token
    }
}
if ($client->getAccessToken()) {
    $me = $plus->people->get('me');
    $optParams = array('maxResults' => 100);
    $activities = $plus->activities->listActivities('me', 'public', $optParams);
    $_SESSION['access_token'] = $client->getAccessToken();
} else {
    $authUrl = $client->createAuthUrl();
}
開發者ID:biswajit-paul,項目名稱:gittest,代碼行數:31,代碼來源:google-plus-access.php


注:本文中的apiClient::refreshToken方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。