Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

MP_Addon_Zoho::get_token( string $code )

Get access token.


Parameters Parameters

$code

(string) (Required) refresh code or authorization code


Top ↑

Source Source

File: calculator-zoho-add-on/inc/MP_Addon_Zoho.php

	private function get_token($code) {

		$token_url = $this->get_api_domain().'/oauth/v2/token';

		$body = array(
			'code' => $code,
			'grant_type' => 'authorization_code',
			'client_id' => $this->get_zoho_client_id(),
			'client_secret' => $this->get_zoho_client_secret(),
			'redirect_uri' => $this->get_redirect_uri(),
		);

		$response = wp_remote_post( $token_url, array( 'body' => $body ) );

		$token_request_data = json_decode($response['body'], true);

		if (empty($token_request_data))
			die("Couldn't decode '$token_request_data' as a JSON object");

		if (!isset($token_request_data['access_token'])||
		    !isset($token_request_data['api_domain']))
			die("Missing expected data from ".print_r($token_request_data, true));

		$refresh_token = $token_request_data['refresh_token'];

		$token_request_data['date_refresh'] = time() + (int)$token_request_data['expires_in'];
		$this->set_zoho_access_token($token_request_data);
		$this->set_refresh_token($refresh_token);
	}

Top ↑

Changelog Changelog

Changelog
Version Description
1.0.0 Introduced.