/** * Generate access_token * * @param string $client_id * @param string $client_secret * @param string $access_code * @param string $redirect_uri * * @return $this * @throws \Exception */ public function generateToken($client_id, $client_secret, $access_code, $redirect_uri) { $endpoint = "oauth2/token"; $request = new Request($this, $this->host, $this->stack); $data = array('client_id' => $client_id, 'client_secret' => $client_secret, 'grant_type' => 'authorization_code', 'code' => $access_code, 'redirect_uri' => $redirect_uri); $json = $request->sendPost($endpoint, $data); $response = json_decode($json, true); if (isset($response['error']) && count($response['error'])) { throw new \Exception("Error occurred: " . $response['error_description']); } $this->token = $response['access_token']; $this->refreshToken = $response['refresh_token']; $this->tokenType = $response['token_type']; $this->expiredIn = $response['expires_in']; return $this; }