LinkedIn OAuth必需的参数"client_id"不见了 [英] LinkedIn OAuth a required parameter "client_id" is missing

查看:55
本文介绍了LinkedIn OAuth必需的参数"client_id"不见了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用LinkedIn API并尝试发出请求,但是当我尝试获取我的访问令牌时,我的json打印中出现以下错误:

I am working with the LinkedIn API and trying to make request but when I try to get my accesstoken I am getting the following error in my json print:

Array ( [error] => missing_parameter [error_description] => A required parameter "client_id" is missing )

这是我的代码:

<?php

    $url = parse_url("https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]");
    parse_str($url['query'], $url);
        
    $code = $url['code'];

    $data = array("grant_type" => "authorization_code", 
                  "code" => $code,
                  "redirect_uri" => "REDIRECT_URI",
                  "client_id" => "SECRET",
                  "client_secret" => "SECRET"
              );
                
    $url2 = "https://www.linkedin.com/oauth/v2/accessToken";

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    curl_setopt($curl, CURLOPT_URL, $url2);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($curl);
    curl_close($curl);
        
    $result_array = json_decode($result, true);

    print_r($result_array);
        
    include('../twitter/navigatie.php');

    echo '<div class="container">';
    
    echo '';

    echo '</div>';

?>

推荐答案

我发现了问题

它必须在字符串中.

所以这个:

curl_setopt($curl, CURLOPT_POSTFIELDS, $data);

成为这个:

curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));

Curl或LinkedIn似乎对此很敏感.

Curl or LinkedIn seemed kinda sensitive for it.

这篇关于LinkedIn OAuth必需的参数"client_id"不见了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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