duanche8554 2017-02-17 09:00
浏览 97

正确获取CURL帖子参数(PHP)

I'm trying to send a post request to the linkedin API using CURL. For some reason I get a response saying that I'm missing one variable.

array:2 [▼
  "error" => "missing_parameter"
  "error_description" => "A required parameter "client_id" is missing"
]

Here is my code and I can assure you that cliend_id is set.

    $code = $request->get("code");
    $state = $request->get("state");
    $redirect_uri = "http://example.com/linkedin/callback";
    $client_id = "1242435657";
    $client_secret = "XXXXXXXXXX";

    $url = "https://www.linkedin.com/oauth/v2/accessToken";

    $params = array(
        "grant_type" => 'authorization_code',
        "code" => $code,
        "redirect_uri" => $redirect_uri,
        "client_id" => $client_id,
        "client_secret" => $client_key,
    );

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, true);

    curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
    $output = curl_exec($ch);
    $info = curl_getinfo($ch);
    curl_close($ch);

    // create an array from the data that is sent back from the API
    $result = json_decode($output, 1);  

Is there anyway that I could debug this post request?

  • 写回答

1条回答 默认 最新

  • dongtuoleng8624 2017-02-17 09:05
    关注

    Remove the comma at the end of the last property and try again perhaps?

    $params = array(
            "grant_type" => 'authorization_code',
            "code" => $code,
            "redirect_uri" => $redirect_uri,
            "client_id" => $client_id,
            "client_secret" => $client_key, <=========
        );
    
    评论

报告相同问题?

悬赏问题

  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计