Linkedin 登录:无法检索访问令牌:appId 或重定向 uri 与授权码不匹配或授权码已过期
Linkedin signin: Unable to retrieve access token : appId or redirect uri does not match authorization code or authorization code expired
我在 http://localhost/index.php 中有以下按钮:
<a href="https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=123456789&state=adasd8asd8sad&scope=r_basicprofile&redirect_uri=http://localhost/linkedin.php">Linked in</a>
然后在 redirect_url 我有以下 php 代码:
<?php
$data = array(
'client_id' => '123456789',
'client_secret' => 'abcdefghijklm',
'grant_type' => 'authorization_code',
'code' => $_REQUEST['code'],
'redirect_uri' => 'http://localhost/index.php',
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.linkedin.com/uas/oauth2/accessToken');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
var_dump($result);die;
然而这会导致:
string(263) "{"error_description":"missing required parameters,
includes an invalid parameter value, parameter more than once. :
Unable to retrieve access token : appId or redirect uri does not match
authorization code or authorization code
expired","error":"invalid_request"}"
我还想说的是,点击link后,最多2秒到linkedin.php中的代码为运行。所以它在 linkedin 要求的 20 秒之内。所以真的不能过期
Linkedin 中的开发人员控制台:
配置的重定向网址为:
http://localhost/linkedin.php 和
http://localhost/index.php
'client_id' => '123456789'(模糊),
'client_secret' => 'abcdefghijklm'(模糊)
默认应用程序权限:r_basicprofile
谁能看出我为什么会出现这个错误?
当您调用 /accessToken
端点时,您必须指定与初始 /authorization
请求相同的 redirect_uri
值。参见OAuth2 RFC。现在你的价值观不同了:
http://localhost/linkedin.php
http://localhost/index.php
我在 http://localhost/index.php 中有以下按钮:
<a href="https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=123456789&state=adasd8asd8sad&scope=r_basicprofile&redirect_uri=http://localhost/linkedin.php">Linked in</a>
然后在 redirect_url 我有以下 php 代码:
<?php
$data = array(
'client_id' => '123456789',
'client_secret' => 'abcdefghijklm',
'grant_type' => 'authorization_code',
'code' => $_REQUEST['code'],
'redirect_uri' => 'http://localhost/index.php',
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.linkedin.com/uas/oauth2/accessToken');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
var_dump($result);die;
然而这会导致:
string(263) "{"error_description":"missing required parameters, includes an invalid parameter value, parameter more than once. : Unable to retrieve access token : appId or redirect uri does not match authorization code or authorization code expired","error":"invalid_request"}"
我还想说的是,点击link后,最多2秒到linkedin.php中的代码为运行。所以它在 linkedin 要求的 20 秒之内。所以真的不能过期
Linkedin 中的开发人员控制台:
配置的重定向网址为: http://localhost/linkedin.php 和 http://localhost/index.php
'client_id' => '123456789'(模糊), 'client_secret' => 'abcdefghijklm'(模糊)
默认应用程序权限:r_basicprofile
谁能看出我为什么会出现这个错误?
当您调用 /accessToken
端点时,您必须指定与初始 /authorization
请求相同的 redirect_uri
值。参见OAuth2 RFC。现在你的价值观不同了:
http://localhost/linkedin.php
http://localhost/index.php