缺少必需的参数,包括无效的参数值,使用 LinkedIn API 的参数不止一次 [英] Missing required parameters, includes an invalid parameter value, parameter more than once with LinkedIn API

查看:24
本文介绍了缺少必需的参数,包括无效的参数值,使用 LinkedIn API 的参数不止一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 OAuth2 使用 LinkedIn API 进行身份验证.代码:

I try to authenticate with LinkedIn API with OAuth2. Code:

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":"缺少必需的参数,包含一个无效的参数值,参数不止一次.:client_id","error":"invalid_request"}"

string(153) "{"error_description":"missing required parameters, includes an invalid parameter value, parameter more than once. : client_id","error":"invalid_request"}"

你能帮我吗?

推荐答案

您需要在 cURL POST 调用中添加以下标头,以确保您在 POST 正文中传递的值得到正确解释:

You need to add the following header in your cURL POST call to ensure that the values you are passing in the body of your POST are interpreted correctly:

内容类型:application/x-www-form-urlencoded

Content-Type: application/x-www-form-urlencoded

有关其他信息,请参阅 https://www.rfc-editor.org/rfc/rfc6749#section-4.1.3 用于实际的 OAuth 2.0 RFC 规范.

For additional info, see https://www.rfc-editor.org/rfc/rfc6749#section-4.1.3 for the actual OAuth 2.0 RFC spec.

这篇关于缺少必需的参数,包括无效的参数值,使用 LinkedIn API 的参数不止一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆