这是我尝试从LinkedIn获取用户数据的方法:
$config = array(
'appKey' => 'appKey',
'appSecret' => 'appSecret',
'callbackUrl' => 'callbackUrl'
);
@session_start();
$linkedin = new LinkedInOAuth2( $config );
if ( $_GET['login_type'] == 'linkedin_login' ) {
$scope = array( 'r_emailaddress', 'r_basicprofile' );
social_js_redirect( $linkedin-getAuthorizeUrl( $config['appKey'], $config['callbackUrl'], $scope ) );
} elseif ( ! empty( $_GET['code'] && ! empty( $_GET['state'] ) ) ) {
$data = $linkedin->getAccessToken( $config['appKey'], $config['appSecret'], $config['callbackUrl'] );
if ( ! empty( $data['access_token'] ) ) {
$linkedin->getProfile(); // Get user data from linkedin to add to database
} else {
// Invalid Authorization
}
}
这是添加到数据库中的错误代码:
Array
(
[0] => Array
(
[errorCode] => 0
[message] => Then token used in this request has been revoked by the user.
[requestId] => xxx
[status] => 401
[timestamp] => 1540051999134
)
)
注意:通过检查我的PHP代码,您将了解LinkedIn已成功获取访问令牌
答案 0 :(得分:0)
您能否尝试在获取令牌后添加5-6秒的延迟。我在stackoverflow / github上看到的有关此问题的大多数问题都必须归因于LinkedIn似乎并没有立即激活它提供的令牌,因此稍等片刻即可。