Bitrix24\Bitrix24::getFirstAccessToken PHP Method

getFirstAccessToken() public method

Authorize and get first access token
public getFirstAccessToken ( $code ) : array
$code
return array
    public function getFirstAccessToken($code)
    {
        $applicationId = $this->getApplicationId();
        $applicationSecret = $this->getApplicationSecret();
        $applicationScope = $this->getApplicationScope();
        $redirectUri = $this->getRedirectUri();
        if (null === $applicationId) {
            throw new Bitrix24Exception('application id not found, you must call setApplicationId method before');
        } elseif (null === $applicationSecret) {
            throw new Bitrix24Exception('application id not found, you must call setApplicationSecret method before');
        } elseif (0 === count($applicationScope)) {
            throw new Bitrix24Exception('application scope not found, you must call setApplicationScope method before');
        } elseif (null === $redirectUri) {
            throw new Bitrix24Exception('application redirect URI not found, you must call setRedirectUri method before');
        }
        //        $url = 'https://'.self::OAUTH_SERVER.'/oauth/token/'.
        $url = 'https://' . $this->getDomain() . '/oauth/token/' . '?client_id=' . urlencode($applicationId) . '&grant_type=authorization_code' . '&client_secret=' . $applicationSecret . '&redirect_uri=' . urlencode($redirectUri) . '&code=' . urlencode($code);
        $requestResult = $this->executeRequest($url);
        // handling bitrix24 api-level errors
        $this->handleBitrix24APILevelErrors($requestResult, 'get first access token');
        return $requestResult;
    }