Api Oauth2访问令牌返回;“无效客户端”;错误
我在获取访问令牌时遇到问题。获取身份验证代码后,当我调用get\u access\u令牌时,它返回“invalid\u client”错误。我对此进行了研究,但没有任何帮助。请看我的代码,帮我解决这个问题。先谢谢你。 这是我的密码:Api Oauth2访问令牌返回;“无效客户端”;错误,api,curl,oauth-2.0,access-token,zoho,Api,Curl,Oauth 2.0,Access Token,Zoho,我在获取访问令牌时遇到问题。获取身份验证代码后,当我调用get\u access\u令牌时,它返回“invalid\u client”错误。我对此进行了研究,但没有任何帮助。请看我的代码,帮我解决这个问题。先谢谢你。 这是我的密码: public function get_access_token($zoho_code) { $headers = array( ); $taskurl = 'https://accounts.zoho.com/oauth/v2/token
public function get_access_token($zoho_code)
{
$headers = array(
);
$taskurl = 'https://accounts.zoho.com/oauth/v2/token';
$cdata = array(
'code' => $zoho_code,
'grant_type' => 'authorization_code',
'client_id' => $this->client_id,
'client_secret' => $this->client_secret_id,
'redirect_uri' => 'http://localhost/callback.php',
'scope' => 'ZohoMail.accounts.UPDATE,ZohoMail.accounts.READ,ZohoMail.partner.organization.READ,ZohoMail.partner.organization.UPDATE,ZohoMail.organization.accounts.CREATE,ZohoMail.organization.accounts.UPDATE,ZohoMail.organization.accounts.READ,ZohoMail.organization.domains.CREATE,ZohoMail.organization.domains.UPDATE,ZohoMail.organization.domains.DELETE,ZohoMail.organization.domains.READ',
'state' => '55555sfdfsdfgbcv',
);
$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_URL, $taskurl);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$res = curl_exec($ch);
$information = curl_getinfo($ch);
print_r($information);
print_r($cdata);
curl_close($ch);
$resj = json_decode($res);
return $resj;
}
如果我正确地阅读了您的代码,那么您将发送您的
client\u secret
,作为POST请求正文的一部分,编码为JSON
您应该使用
application/x-www-form-urlencoded
正文发出POST请求,并且您应该将Authorization
标题和client\u secret
编码在基本方案中。有关更多信息,请参阅。我尝试了您所写的内容。它也不起作用。在ZohoMail API文档中,我还编写了如下形式使用它:POST oauth/v2/token HOST::Query String:?code=1000.******************************************f160&grant_type=authorization_code&client_id=1000.R2Z0W.***************************************Q5EN&client_secret=39c*******************************************921b&redirect_uri=&scope=VirtualOffice.folders.READ