public function fetchAccessTokenWithAuthCode($code)
  {
    if (strlen($code) == 0) {
      throw new InvalidArgumentException("Invalid code");
    }

    $auth = $this->getOAuth2Service();
    $auth->setCode($code);
    $auth->setRedirectUri($this->getRedirectUri());

    $httpHandler = HttpHandlerFactory::build($this->getHttpClient());
    $creds = $auth->fetchAuthToken($httpHandler);
    if ($creds && isset($creds['access_token'])) {
      $creds['created'] = time();
      $this->setAccessToken($creds);
    }

    return $creds;
  }
public function fetchAccessTokenWithAuthCode($code)
  {
    if (strlen($code) == 0) {
      throw new InvalidArgumentException("Invalid code");
    }

    $auth = $this->getOAuth2Service();
    $auth->setCode($code);
    $auth->setRedirectUri($this->getRedirectUri());

    $httpHandler = HttpHandlerFactory::build($this->getHttpClient());
    $creds = $auth->fetchAuthToken($httpHandler);
    if ($creds && isset($creds['access_token'])) {
      $creds['created'] = time();
      $this->setAccessToken($creds);
    }

    return $creds;
  }
public function fetchAccessTokenWithAuthCode ( $ code ) { if ( strlen ( $ code ) == 0 ) { throw new InvalidArgumentException ( "Invalid code" ) ; } $ auth = $ this -> getOAuth2Service ( ) ; $ auth -> setCode ( $ code ) ; $ auth -> setRedirectUri ( $ this -> getRedirectUri ( ) ) ; $ httpHandler = HttpHandlerFactory :: build ( $ this -> getHttpClient ( ) ) ; $ creds = $ auth -> fetchAuthToken ( $ httpHandler ) ; if ( $ creds && isset ( $ creds [ 'access_token' ] ) ) { $ creds [ 'created' ] = time ( ) ; $ this -> setAccessToken ( $ creds ) ; } return $ creds ; }
Attempt to exchange a code for an valid authentication token.
Helper wrapped around the OAuth 2.0 implementation.

@param $code string code from accounts.google.com
@return array access token
Attempt to exchange a code for an valid authentication token . Helper wrapped around the OAuth 2 . 0 implementation .