【问题标题】:What is the correct format and sequence to acquire the correct token for LinkedIn API V2?为 LinkedIn API V2 获取正确令牌的正确格式和顺序是什么?
【发布时间】:2019-10-12 00:57:33
【问题描述】:

我们的 LinkedIn APP 不再适用于 V2 的演变。我已经尝试了几次,但未能创建正确的令牌。我正在寻求帮助以创建正确的授权链接以获取令牌。来自应用程序的错误当前是“Empty oauth2 access token”

我创建了一个新的 LinkedIn 应用来替换我们的旧应用。我尝试按照 LinkedIn 和 Microsoft 的说明进行操作,但我的努力产生了以下错误

我最近的尝试是:

https://www.linkedin.com/oauth/v2/authorization?response_type=code&client_id=78xaqf0ereiisy&redirect_uri=https://www.gachina.com&state=gachina&scope=r_emailaddressr_liteprofile w_member_social

我收到了:https://www.gachina.com/?code=AQS65Njp1F9-L-mKSrAJKZeQ-ij2OX7wboTc30-hrfQIwwJ0yfWd4FBqxLl-ZXHmL5HurKud4t9WcGeHB62EfPNcy3ddoqT1LztUHhR59iL-Q8f9WLrX03d9e3OCTmY-3vR8a_4ENeIN0GFpeLy7DKRDmuUNcQ82UwScqhApdtwzEBw-_Y0duYG87Lc1KQ&state=gachina

然后我使用这里显示的格式:

https://docs.microsoft.com/en-us/linkedin/shared/authentication/authorization-code-flow

https://www.linkedin.com/oauth/v2/accessToken?grant_type=authorization_code&code={authorization_code_from_step2_response}&redirect_uri=hhttps%3A%2F%2Fdev.example.com%2Fauth%2Flinkedin%2Fcallback&client_id={your_client_id}&client_secret={your_client_secret}

https://www.linkedin.com/oauth/v2/accessToken?grant_type=authorization_code&code=AQS65Njp1F9-L-mKSrAJKZeQ-ij2OX7wboTc30-hrfQIwwJ0yfWd4FBqxLl-ZXHmL5HurKud4t9WcGeHB62EfPNcy3ddoqT1LztUHhR59iL-Q8f9WLrX03d9e3OCTmY-3vR8a_4ENeIN0GFpeLy7DKRDmuUNcQ82UwScqhApdtwzEBw-_Y0duYG87Lc1KQ&redirect_uri=https://www.gachina.com/auth/Linkedin/callback&client_id=78xaqf0ereiisy&client_secret={client_secret}

但我在提交上述链接时收到以下内容,并附上我们的 {client secret}

{"error":"invalid_redirect_uri","error_description":"Unable to retrieve access token: appid/redirect uri/code verifier does not match authorization code. Or authorization code expired. Or external member binding exists"}

我将在几分钟内完成所有这些工作。所以,我不相信代码会过期。

您能否帮助识别接收 Token 的步骤或代码错误?

【问题讨论】:

    标签: linkedin


    【解决方案1】:

    这将返回访问令牌

    $params = array('grant_type' => 'authorization_code',
                'client_id' => $this->api_key,
                'client_secret' => $this->api_secret,
                'code' => $_GET['code'],
                'redirect_uri' => base_url().$this->redirect,
            );
            // Access Token request
            $url = 'https://www.linkedin.com/oauth/v2/accessToken?' . http_build_query($params);
            $data_len = strlen(http_build_query($params));
            // Tell streams to make a POST request
            $context = stream_context_create(
                    array('http' =>
                        array('method' => 'POST','header'=> 'Content-Length: 0'
                        )
                    )
            );
    
            // Retrieve access token information
            $response = file_get_contents($url, false, $context);
            $token = json_decode($response);
            return $token->access_token;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-28
      • 2021-05-18
      • 1970-01-01
      • 1970-01-01
      • 2015-05-05
      • 2021-09-22
      • 1970-01-01
      相关资源
      最近更新 更多