提问人:Pankaj 提问时间:11/6/2023 最后编辑:hakrePankaj 更新时间:11/12/2023 访问量:107
尝试从 Intuit API 获取令牌时出现“invalid_client”错误
"invalid_client" error while trying to fetch token from Intuit API
问:
我正在使用 Curl/PHP 获取令牌以与 QuickBooks Intuit API 进行通信。
我能够召唤以下响应(JSON 文本错误):
{"error":"invalid_client"}
这是如何做到的:
起始页
$parameters = array(
'client_id' => "my client id",
'scope' => "com.intuit.quickbooks.accounting",
'redirect_uri' => "http://localhost/redirect.php",
'response_type' => "code",
'state' => "RandomState"
);
$authorizationRequestUrl = 'https://appcenter.intuit.com/connect/oauth2?' . http_build_query($parameters);
header("Location: ".$authorizationRequestUrl);
重定向终结点(页面)获取访问令牌
$queries = array();
parse_str($_SERVER['QUERY_STRING'], $queries);
$client_id = "My Sandbox client id";
$client_secret = "My Sandbox secret";
$redirect_url = "http://localhost/redirect.php";
$access_token_url = "https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer";
$scope = "com.intuit.quickbooks.accounting openid profile email phone address";
$authorizationHeader = "Basic ".base64_encode($client_id.":".$client_secret);
$data = array(
'redirect_uri' => $redirect_url,
'grant_type' => 'authorization_code',
"code" => $queries["code"]
);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $access_token_url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => http_build_query($data),
CURLOPT_HTTPHEADER => array(
"Authorization" => $authorizationHeader,
"Accept" => "application/json",
"Content-Type" => "application/x-www-form-urlencoded",
"Connection" => "keep-alive"
),
));
$response = curl_exec($curl);
print_r($response); # see JSON Text error above
如何使用QuickBooks Intuit API防止错误代码?invalid_client
答:
0赞
Pankaj
11/11/2023
#1
我刚刚弄清楚了这个问题。我在请求中缺少证书文件。这是强制性的,否则我们会得到一个错误。invalid_client
评论
0赞
hakre
11/12/2023
这是个好消息。请考虑留下一个片段,说明您是如何做到的,并且因为它对您来说仍然很新鲜,因此可以链接到您认为最接近(客户端?)证书的文档部分,或者您如何获得它(证书)。如果是客户端证书,错误代码确实具有误导性,因为它不是客户端,而是授权,但是如果您在答案中添加更多内容,这应该会变得更加清晰。
评论
code
$data
$authorizationRequestUrl