Zoho crm:STUCK在第3​​步:生成访问令牌和刷新令牌

I have $code and other variables values, but i receive error " Server error occurred Looks like you typed an incorrect address Or the URL you clicked is invalid."

enter image description here

$adminUrl='https://accounts.zoho.com/oauth/v2/token';


$data = array("code" => $code,
"redirect_uri" => $redirect_url, 
"client_id"=>$client_id, 
"client_secret" =>$client_secret, 
"grant_type"=> "authorization_code",
"scope" => "ZohoCRM.modules.ALL");

$data_string = json_encode($data,JSON_UNESCAPED_SLASHES);

$headers = array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string)

);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $adminUrl);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);

$token = curl_exec($ch);

Based on the API https://www.zoho.com/mail/help/api/using-oauth-2.html

Generate the token

GET oauth/v2/auth 
Host:: https://accounts.zoho.com

Query String:

https://accounts.zoho.com/oauth/v2/auth
?response_type=code 
&client_id=1000.R2*************************5EN
&scope=VirtualOffice.folders.READ
&redirect_uri=https://zylkerapps.com/oauth2callback
&state=-54****************5

Code example

$redirectTo = 'https://accounts.zoho.com/oauth/v2/auth' . '?' . http_build_query(
    [
     'client_id'     => $client_id,
     'redirect_uri'  => $redirect_url,
     'scope'         => 'ZohoCRM.modules.ALL',
     'response_type' => 'code',
    ]);
header('Location: ' . $redirectTo);
exit;

Refresh the token

POST https://accounts.zoho.com/oauth/v2/token

HOST:: https://accounts.zoho.com

Query String:

?refresh_token=1000.4069dacb56****************************************bcf902062390367
&grant_type=refresh_token
&client_id=1000.R2Z0W*********************Q5EN
&client_secret=39c**********************************921b
&redirect_uri=https://zylkerapps.com/oauth2callback
&scope=VirtualOffice.folders.UPDATE

Code example

$params = [
    'refresh_token' => $refresh_token,
    'grant_type'    => 'refresh_token',
    'client_id'     => $client_id,
    'client_secret' => $client_secret,
    'redirect_uri'  => $redirect_url,
    'scope'         => 'ZohoCRM.modules.ALL'
];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://accounts.zoho.com/oauth/v2/token');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$response = curl_exec($ch);
curl_close ($ch);

//Remember to change values/url's as per your zoho account.

To get client id and secret id : https://accounts.zoho.com/developerconsole

Once we have client-id , we will use it to generate oauth_token ( access_token ).

You will need 2 files given below to get oath_token ( also called access_token ).

file_1 ( zohoauth.php )

https://drive.google.com/file/d/1yOfPBllcL3KEKIm_ooDxLJzc8a4NCDIu/view?usp=sharing

file_2 ( testaccesstoken.php )

https://drive.google.com/file/d/1fBxBbt7IKI7vwgx6inaDnjtylSlSe4ye/view?usp=sharing