Answer the question
In order to leave comments, you need to log in
Why do I get "invalid _client" error when requesting token access in Oauth2 ZohoMail API?
Hello everybody. Please help me to solve this (already boring) error. After successfully receiving the authorization code, I make a POST request to access the token (access_token). But the request returns "invalid_client" to me, I searched the entire Internet, tried everything, but nothing helped. Same error. And I wrote to support ZohoMail API. Didn't answer anything :( I also read all the ZohoMail APİ documentation thoroughly, and also reviewed the oauth2.0 protocol documentation. And it seems according to this documentation everything is correct for me. And the php code seems to be working, but maybe I'm passing the wrong parameters? And by the way, is this error possible due to a trial subscription? I also ask you, experts in this matter, to consider my code, maybe someone will find my mistake. I need to solve it urgently :( I will be very grateful to you. Thanks in advance :)
public function get_access_token()
{
$headers = array(
/*'Authorization: Basic ' . $this->client_secret,*/
/* 'Content-Type: application/x-www-form-urlencoded'*/
);
$taskurl = 'https://accounts.zoho.com/oauth/v2/token';
$cdata = array(
'code' => $this->zoho_oauth_code,
'redirect_uri' => 'https://testingapi.ml/callback',
'grant_type' => 'authorization_code',
'client_id' => $this->client_id,
'client_secret' => $this->client_secret,
'scope' => 'ZohoMail.accounts.all,ZohoMail.organization.accounts.all,ZohoMail.organization.domains.all',
'state' => $this->generateRandomString()
);
$curlresult = $this->docurl($taskurl, $cdata, $headers);
return $curlresult;
}
public function docurl($taskurl, $cdata, $headers, $method = 'post',$sendjson=true)
{
$ch = curl_init();
if ($method == 'get') {
if ($cdata) {
$query = '?' . http_build_query($cdata);
$taskurl .= $query;
}
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
} elseif ($method == 'delete') {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
} elseif ($method == 'put') {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
} elseif ($method == 'patch') {
if($sendjson) $cdata = json_encode($cdata);
curl_setopt($ch, CURLOPT_POSTFIELDS, $cdata);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
} else {
if($sendjson) {
$cdata = json_encode($cdata);
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $cdata);
curl_setopt($ch, CURLOPT_POST, true);
/* curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);*/
}
curl_setopt($ch, CURLOPT_URL, $taskurl);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$res = curl_exec($ch);
$information = curl_getinfo($ch);
curl_close($ch);
$resj = json_decode($res);
return $resj;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question