PHP   发布时间:2022-04-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了领英获取令牌返回HTTP 1.1 400-错误的请求错误大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

我目前在获取LinkedIn令牌时遇到问题.

我目前正在追踪developers documentation in order to get through authentication.

我也使用this sample作为基本代码

但是,经过授权过程(其中获得身份验证码)之后,获取用户令牌的过程失败,并出现错误请求错误(400)

这是示例页面中的修改后的代码
(注意:在移至cURL之前,我们之前做过的评论部分)

 public function getAccessToken() {
        $params = array('grant_type' => 'authorization_code',
            'client_id' => API_KEY,
            'client_secret' => API_SECRET,
            'code' => $_GET['code'],
            'redirect_uri' => REDIRECT_URI.'/linkedin/auth',
        );


        // Access Token request
        $url = urldecode('https://www.linkedin.com/uas/oauth2/accessToken?'.http_build_query($params));
        //header("Content-length: ".strlen($url));
        // Tell streams to make a POST request


        echo $url;

        /*$context = stream_context_create(
            array('http' =>
            array('method' => 'POST',
            )
            )
        );*/

        /*$context  = stream_context_create(
                        array('http' =>
                            array('method'  => 'POST',
                                  'header'  => 'Content-type: application/x-www-form-urlencoded',
                                  'content' => http_build_query($params))
                        )
                    );

        // Retrieve access token information
        $response = file_get_contents($url, falSE, $context);*/


        $ch = curl_init();

        curl_setopt($ch,CURLOPT_URL, $url);
        curl_setopt($ch,CURLOPT_POST,1);
        $response = curl_exec($ch);

        curl_close($ch);

        $token = json_decode($responsE);

        echo json_decode($responsE);

        // Store access token and expiration time
        $_SESSION['access_token'] = $token->access_token; // guard this!
        $_SESSION['expires_in']   = $token->expires_in; // relative time (in seconds)
        $_SESSION['expires_at']   = time() + $_SESSION['expires_in']; // absolute time

        return true;
}

忘了说了,echo $url;部分,输出一个网址,该网址在手动插入浏览器中时会生成有效的用户令牌

解决方法:

为了使请求正常工作,必须以GET而不是POST的形式发送请求.

删除此行:

curl_setopt($ch,CURLOPT_POST,1);

大佬总结

以上是大佬教程为你收集整理的领英获取令牌返回HTTP 1.1 400-错误的请求错误全部内容,希望文章能够帮你解决领英获取令牌返回HTTP 1.1 400-错误的请求错误所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: