/**
  * @return \Google_Service_Analytics
  * @throws \Exception
  * @throws \Google_Exception
  */
 public function getService($token = null)
 {
     $application = $this->applicationService->getApplication(self::RESOURCE_OWNER);
     if ($token === null) {
         $token = $this->getToken();
     }
     $authConfig = array('web' => array('client_id' => $application->getKey(), 'client_secret' => $application->getSecret()));
     $client = new \Google_Client();
     $client->setAuthConfig(json_encode($authConfig));
     $client->setAccessToken(json_encode(array('access_token' => $token->getAccessToken(), 'refresh_token' => $token->getRefreshToken())));
     return new \Google_Service_Analytics($client);
 }
 /**
  * Return a connection based on the suplied Token
  *
  * @param Token $token
  *
  * @return LinkedInClientService
  */
 public function getConnectionByToken(Token $token)
 {
     $application = $this->oauthApp->getApplication(self::RESOURCE_OWNER);
     $connection = $this->connect($application->getKey(), $application->getSecret(), $token->getAccessToken(), $token->getTokenSecret());
     return new LinkedInClientService($connection);
 }