【问题标题】:LinkedIn API PHP领英 API PHP
【发布时间】:2017-02-15 21:00:45
【问题描述】:

我在尝试使用 LinkedIn API 对用户进行身份验证时遇到这个奇怪的错误。数据的 var_dump() 显示了这一点:

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

我不确定为什么会发生这种情况,任何人都可以帮助我解决这个问题。

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, "https://www.linkedin.com/uas/oauth2/accessToken?");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/x-www-form-urlencoded',
    ));
    curl_setopt($ch, CURLOPT_POSTFIELDS, array(
        'grant_type'    => 'authorization_code',
        'client_id'     => $account['linkedin']['api_key'],
        'client_secret' => $account['linkedin']['api_secret'],
        'code'          => $_GET['code'],
        'redirect_uri'  => get_admin_url() . 'admin.php?page=' . self::$accounts_dashboard_page . '&linkedin=authorization&account=' . urlencode($account['id']),
    ));

    $response = curl_exec($ch);
    curl_close($ch);

    var_dump($response);

【问题讨论】:

    标签: curl oauth-2.0 linkedin-api


    【解决方案1】:

    我也遇到了同样的错误,但我改变了发送参数的方式。我没有发送数组,而是像典型的 QUERY_STRING 一样发送它们。

    我的意思是:

    curl_setopt($ch, CURLOPT_POSTFIELDS,'grant_type=authorization_code&client_id=XXXXXXX&client_secret=ZZZZZZZ&code=YYYYY&redirect_uri=/path/to/your/redirect/uri')
    

    我不知道为什么,但它对我有用...

    【讨论】:

      【解决方案2】:
      $url = "https://www.linkedin.com/uas/oauth2/accessToken";
      $header = array( "Content-Type: application/x-www-form-urlencoded" );
      
          $data = http_build_query( array(
              "client_id" => {client_id}',
              "client_secret" => {client_secret},
              "redirect_uri" => {redirect_uri},
              "grant_type" => "authorization_code",
              "code" =>$_GET['code']
          ));
      
          $curl = curl_init();
          curl_setopt($curl, CURLOPT_URL, $url);
          curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
          curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
          curl_setopt($curl, CURLOPT_HEADER, 0);
      
          if( $header !== 0 ){
          curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
          }
      
          curl_setopt($curl, CURLOPT_POST, true);
      
          if( $data !== 0 ){
          curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
          }
      
          $response = curl_exec($curl);
      
          curl_close($curl);
      
          $respo = json_decode($response);
      
      echo     $accesstoken = $respo->access_token;
      

      【讨论】:

        猜你喜欢
        • 2020-06-12
        • 1970-01-01
        • 2012-04-09
        • 2020-05-24
        • 1970-01-01
        • 2022-08-08
        • 2019-06-30
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多