OAuth::getAccessToken PHP Méthode

getAccessToken() public static méthode

获取请求token的url
public static getAccessToken ( $code, $redirect_uri ) : string
$code 调用authorize时返回的code
$redirect_uri 回调地址,必须和请求code时的redirect_uri一致
Résultat string
    public static function getAccessToken($code, $redirect_uri)
    {
        $params = array('client_id' => self::$client_id, 'client_secret' => self::$client_secret, 'grant_type' => 'authorization_code', 'code' => $code, 'redirect_uri' => $redirect_uri);
        return self::$accessTokenURL . '?' . http_build_query($params);
    }

Usage Example

Exemple #1
0
 public function actionCallback($oauth_token)
 {
     try {
         $login_secret = $this->getSession('oauth')->login_secret;
         if (!$oauth_token) {
             echo "Error! There is no OAuth token!";
             exit;
         }
         if (!$login_secret) {
             echo "Error! There is no OAuth secret!";
             exit;
         }
         $this->oauth->enableDebug();
         $this->oauth->setToken($oauth_token, $login_secret);
         $access_token_info = $this->oauth->getAccessToken(self::ACCESS_TOKEN_URL);
         $this->getSession('oauth')->login_secret = false;
         $this->getSession('oauth')->token = $access_token_info['oauth_token'];
         $this->getSession('oauth')->secret = $access_token_info['oauth_token_secret'];
         $this->getUserDetailsAndLoginUser();
     } catch (OAuthException $E) {
         Debugger::log($E);
         //zalogujeme for sichr
         echo "OAuth login failed. Please, contact administrator.";
         $this->terminate();
     }
 }
All Usage Examples Of OAuth::getAccessToken