public function getAccessToken($code, $callback_url = 'https://api.vk.com/blank.html')
    {
        if (!is_null($this->access_token) && $this->auth) {
            throw new VKException('Already authorized.');
        }

        $parameters = array(
            'client_id' => $this->app_id,
            'client_secret' => $this->api_secret,
            'code' => $code,
            'redirect_uri' => $callback_url
        );

        $rs = json_decode($this->request(
            $this->createUrl(self::ACCESS_TOKEN_URL, $parameters)), true);

        if (isset($rs['error'])) {
            throw new VKException($rs['error'] .
                (!isset($rs['error_description']) ?: ': ' . $rs['error_description']));
        } else {
            $this->auth = true;
            $this->access_token = $rs['access_token'];
            return $rs;
        }
    }
public function getAccessToken($code, $callback_url = 'https://api.vk.com/blank.html')
    {
        if (!is_null($this->access_token) && $this->auth) {
            throw new VKException('Already authorized.');
        }

        $parameters = array(
            'client_id' => $this->app_id,
            'client_secret' => $this->api_secret,
            'code' => $code,
            'redirect_uri' => $callback_url
        );

        $rs = json_decode($this->request(
            $this->createUrl(self::ACCESS_TOKEN_URL, $parameters)), true);

        if (isset($rs['error'])) {
            throw new VKException($rs['error'] .
                (!isset($rs['error_description']) ?: ': ' . $rs['error_description']));
        } else {
            $this->auth = true;
            $this->access_token = $rs['access_token'];
            return $rs;
        }
    }
public function getAccessToken ( $ code , $ callback_url = 'https://api.vk.com/blank.html' ) { if ( ! is_null ( $ this -> access_token ) && $ this -> auth ) { throw new VKException ( 'Already authorized.' ) ; } $ parameters = array ( 'client_id' => $ this -> app_id , 'client_secret' => $ this -> api_secret , 'code' => $ code , 'redirect_uri' => $ callback_url ) ; $ rs = json_decode ( $ this -> request ( $ this -> createUrl ( self :: ACCESS_TOKEN_URL , $ parameters ) ) , true ) ; if ( isset ( $ rs [ 'error' ] ) ) { throw new VKException ( $ rs [ 'error' ] . ( ! isset ( $ rs [ 'error_description' ] ) ? : ': ' . $ rs [ 'error_description' ] ) ) ; } else { $ this -> auth = true ; $ this -> access_token = $ rs [ 'access_token' ] ; return $ rs ; } }
Returns access token by code received on authorization link.
@param   string $code
@param   string $callback_url
@throws  VKException
@return  array
Returns access token by code received on authorization link .