缺少必需的参数,包括无效的参数值,在 LinkedIn 上多次使用参数 API
Missing required parameters, includes an invalid parameter value, parameter more than once with LinkedIn API
我尝试使用 OAuth2 通过 LinkedIn API 进行身份验证。代码:
if ((isset($_GET["code"])) AND (isset($_GET["state"]))) {
$code = $_GET["code"];
$state = $_GET["state"];
$curl_request = curl_init();
curl_setopt_array($curl_request, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => "https://www.linkedin.com/uas/oauth2/accessToken",
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => array(
grant_type => "authorization_code",
code => "$code",
redirect_uri => "SECRET",
client_id => "SECRET",
client_secret => "SECRET"
)
));
$curl_result = curl_exec($curl_request);
var_dump($curl_result);
}
我收到这条消息:
string(153) "{"error_description":"missing required parameters,
includes an invalid parameter value, parameter more than once. :
client_id","error":"invalid_request"}"
你能帮我吗?
您需要在您的 cURL POST 调用中添加以下 header 以确保您在 POST 的 body 中传递的值被正确解释:
Content-Type: application/x-www-form-urlencoded
有关其他信息,请参阅 https://www.rfc-editor.org/rfc/rfc6749#section-4.1.3 了解实际的 OAuth 2.0 RFC 规范。
使用:http_build_query
curl_setopt_array($curl, array(
CURLOPT_HTTPHEADER => array('Content-Type: application/x-www-form-urlencoded'),
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://www.linkedin.com/uas/oauth2/accessToken',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => http_build_query (array(
client_id => "secret",
client_secret => "secret",
grant_type => "authorization_code",
redirect_uri => "url",
code => $code
)),
));
我对此感到很奇怪,但我遇到了同样的问题,当我将客户端 ID 和密码移动到 POST 数组的开头时,一切正常。我什至没有。
我尝试使用 OAuth2 通过 LinkedIn API 进行身份验证。代码:
if ((isset($_GET["code"])) AND (isset($_GET["state"]))) {
$code = $_GET["code"];
$state = $_GET["state"];
$curl_request = curl_init();
curl_setopt_array($curl_request, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => "https://www.linkedin.com/uas/oauth2/accessToken",
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => array(
grant_type => "authorization_code",
code => "$code",
redirect_uri => "SECRET",
client_id => "SECRET",
client_secret => "SECRET"
)
));
$curl_result = curl_exec($curl_request);
var_dump($curl_result);
}
我收到这条消息:
string(153) "{"error_description":"missing required parameters, includes an invalid parameter value, parameter more than once. : client_id","error":"invalid_request"}"
你能帮我吗?
您需要在您的 cURL POST 调用中添加以下 header 以确保您在 POST 的 body 中传递的值被正确解释:
Content-Type: application/x-www-form-urlencoded
有关其他信息,请参阅 https://www.rfc-editor.org/rfc/rfc6749#section-4.1.3 了解实际的 OAuth 2.0 RFC 规范。
使用:http_build_query
curl_setopt_array($curl, array(
CURLOPT_HTTPHEADER => array('Content-Type: application/x-www-form-urlencoded'),
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://www.linkedin.com/uas/oauth2/accessToken',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => http_build_query (array(
client_id => "secret",
client_secret => "secret",
grant_type => "authorization_code",
redirect_uri => "url",
code => $code
)),
));
我对此感到很奇怪,但我遇到了同样的问题,当我将客户端 ID 和密码移动到 POST 数组的开头时,一切正常。我什至没有。