【问题标题】:How to implement Client Credential Flow (2-legged OAuth) to connect to LinkedIn API?如何实现客户端凭据流(2 腿 OAuth)以连接到 LinkedIn API?
【发布时间】:2020-10-27 13:28:10
【问题描述】:
  1. 当我尝试official pageother example 时。

  2. 我明白了

    {"error":"access_denied","error_description":"该应用不允许创建应用令牌"}

  3. 我在下面添加了代码,但没有获得访问令牌。这表明应用程序不允许创建应用程序令牌。

{
  String urlParameters = "grant_type=client_credentials&client_id="+linkedInClientId+"&client_secret="+linkedInClientSecret;
  String urlParametersEncoded = "";

  try {
    urlParametersEncoded = URLEncoder.encode(urlParameters, "UTF-8");
  } catch (Exception e) {
    System.out.println("URL Encode error.." + e);
  }

  String url = "https://www.linkedin.com/oauth/v2/accessToken?" + urlParametersEncoded;
  String access_token = "null";
  try {
    URL obj = new URL(url);
    HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();

    //add reuqest header
    con.setRequestMethod("POST");
    con.setRequestProperty("Host", "www.linkedin.com");
    con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

    // Send post request
    con.setDoOutput(true);
    DataOutputStream wr = new DataOutputStream(con.getOutputStream());
    wr.writeBytes(urlParameters);
    wr.flush();
    wr.close();

    int responseCode = con.getResponseCode();
    System.out.println("\nSending 'POST' request to URL : " + url);
    System.out.println("Post parameters : " + urlParameters);
    System.out.println("Response Code : " + responseCode);

    BufferedReader in = new BufferedReader(
      new InputStreamReader(con.getInputStream()));
    String inputLine;
    StringBuffer response = new StringBuffer();

    while ((inputLine = in.readLine()) != null) {
      response.append(inputLine);
    }
              in.close();

    //print result
    //System.out.println(response.toString());

    JSONObject jsonObj = new JSONObject(response.toString());
    access_token = jsonObj.getString("access_token");
    System.out.println("!!!!!!!!!!!" + access_token);
  } catch (Exception e) {
    System.out.println("error token.." + e);
  }

  return access_token;
}

【问题讨论】:

  • 你能添加一些相关的代码,让人们看到你想要实现的目标吗?
  • @StephanHogenboom 我添加了代码
  • 您在第2步中遇到错误,您是否在第1步中正确创建了应用程序?
  • @forkdbloke 我正确创建了应用程序,但默认添加了 3-legged 权限。我不知道如何创建 2-legged 权限

标签: java spring-boot linkedin linkedin-api


【解决方案1】:

两条腿的流程 - 不是特定于成员,但需要某种形式的批准

所有两条腿的流都需要伙伴关系/扩展访问权限 (https://developer.linkedin.com/partner-programs)

详细了解 LinkedIn Developer Enterprise 产品以请求客户凭据流的权限。

三足流 - 会员专属

三足流不像两足流那样需要任何扩展访问,最好使用三足流代替(推荐)。

请按照三足流的步骤操作,它对我有用,

在浏览器中访问它

https://www.linkedin.com/oauth/v2/authorization?response_type=code&client_id=81101e5urkn5nv&redirect_uri=https://localhost:8080/auth/callback&state=aRandomString&scope=r_emailaddress

【讨论】:

  • 以上链接未提供详细说明。我想创建 2-legged 客户端凭据流。
  • 但我想在没有用户交互的情况下获取访问令牌
  • All two-legged flows would require partnership/extended access 这是什么意思?只需在linkedin上添加应用程序,以获取我假设的您的client_id和client_secret?
  • 您是否有幸为 LinkedIn 获得 2-legged OAuth 身份验证工作?我已经在仪表板中为我的应用程序添加了所有产品,但我仍然无法获得应用程序令牌来访问任何标准 API,例如技能 API。我正在关注这个文档docs.microsoft.com/en-us/linkedin/shared/authentication/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-04
  • 2022-08-06
  • 1970-01-01
  • 1970-01-01
  • 2014-12-27
  • 2016-08-27
相关资源
最近更新 更多