user1419810
user1419810

Reputation: 846

Google Analytics API refresh token API Fatal Error

I'm using the Google Analytics API and am getting refresh tokens as explained in the documentation. I am however facing an error if a user has revoked access from their Google account but still tries to use my integration (which is actually a possibility). When I call:

$client->setAccessToken($newtoken);

To get a new token using the refresh token a fatal error is thrown and I cannot catch this error.

Ideally I would like to check the user's refresh token access, however I can't work out how to do this, is this possible with the php library?

Upvotes: 0

Views: 59

Answers (1)

Ali Erdem
Ali Erdem

Reputation: 156

as i can see from the code of the library you have to catch InvalidArgumentException

  public function setAccessToken($token)
  {
    if (is_string($token)) {
      if ($json = json_decode($token, true)) {
        $token = $json;
      } else {
        // assume $token is just the token string
        $token = array(
          'access_token' => $token,
        );
      }
    }
    if ($token == null) {
      throw new InvalidArgumentException('invalid json token');
    }
    if (!isset($token['access_token'])) {
      throw new InvalidArgumentException("Invalid token format");
    }
    $this->token = $token;
  }

Upvotes: 1

Related Questions