gpt4 book ai didi

api - Oauth2 访问 token 返回 "invalid client"错误

转载 作者:行者123 更新时间:2023-12-02 19:59:27 25 4
gpt4 key购买 nike

我在获取访问 token 时遇到问题。获取授权码后,当我调用 get_access_token 时,它返回“invalid_client”错误。我对此进行了研究,但没有任何帮助。请查看我的代码并帮助我解决这个问题。先感谢您。这是我的代码:

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;

}

最佳答案

如果我正确地阅读了您的代码,则您将作为编码为 JSON 的 POST 请求正文的一部分发送您的 client_secret

您应该使用 application/x-www-form-urlencoded 正文发出 POST 请求,并且应包含带有 client_secretAuthorization header > 在基本方案中编码。有关详细信息,请参阅OAuth2 RFC .

关于api - Oauth2 访问 token 返回 "invalid client"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56215583/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com