到linkedin注册成为开发者:https://developer.linkedin.com/zh-cn
成功后,创建应用,填写重定向地址,得到appid和appkey
使用这个sdk https://github.com/ashwinks/PHP-LinkedIn-SDK
利用composer安装
composer require linkedinapi/linkedin ^1.1
写个首页,点击跳到login.php
$li = new LinkedIn( array( 'api_key' => 'yourapikey', 'api_secret' => 'yourapisecret', 'callback_url' => 'https://yourdomain.com/redirecthere' ) ); $url = $li->getLoginUrl( array( LinkedIn::SCOPE_BASIC_PROFILE, LinkedIn::SCOPE_EMAIL_ADDRESS ) ); header("Location:$url ");
这会跳转到授权页面
点击授权后,跳转到回调地址
$li = new LinkedIn( array( 'api_key' => 'yourapikey', 'api_secret' => 'yourapisecret', 'callback_url' => 'https://yourdomain.com/redirecthere' ) ); $token = $li->getAccessToken($_GET['code']); if(isset($token ['error'])) { return $token ['error'] } $data = $li->get('/people/~:(id,firstName,lastName,pictureUrls::(original),email-address)'); var_dump($data);
会打印出登陆用户的信息