我正在使用 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
错误代码?
我刚刚发现了这个问题。我在请求中缺少证书文件。这是强制性的,否则我们会收到无效的客户端错误