含r_liteprofile scope的LinkedIn OAuth v2调用失败求助
解决方案:LinkedIn OAuth v2中
r_liteprofile报错问题 问题根源
r_liteprofile是LinkedIn旧版API的权限范围,目前已被官方废弃,LinkedIn OAuth v2现在统一使用OpenID Connect标准权限来获取用户基础信息,继续使用旧scope会触发授权错误。
修复步骤
替换权限范围
将原scope替换为OpenID兼容的组合:const scope = 'openid profile email w_member_social';openid:启用OpenID Connect流程(必须包含,否则无法使用profile和email)profile:替代原r_liteprofile,用于获取用户姓名、头像等基础资料email:替代原r_emailaddress,用于获取用户绑定的邮箱w_member_social:保留原有的发布动态权限
验证应用后台配置
- 登录LinkedIn开发者后台,进入你的应用
- 确认Auth页面中已启用
OpenID Connect功能 - 检查重定向URI(
REDIRECT_URI)已在后台正确配置,且和代码中完全一致(包括协议、域名、路径)
更新后的完整代码示例
const scope = 'openid profile email w_member_social'; // 使用OpenID标准权限 const state = uuidv4(); sessionStorage.setItem('linkedin_oauth_state', state); const linkedInAuthUrl = `https://www.linkedin.com/oauth/v2/authorization?response_type=code&client_id=${CLIENT_ID}&redirect_uri=${encodeURIComponent( REDIRECT_URI )}&state=${state}&scope=${encodeURIComponent(scope)}`; // 打开授权弹窗 const width = 600; const height = 600; const left = window.screen.width / 2 - width / 2; const top = window.screen.height / 2 - height / 2; window.open( linkedInAuthUrl, 'LinkedInAuth', `width=${width},height=${height},top=${top},left=${left}` );
额外说明
授权成功后,你可以通过LinkedIn的OpenID Connect用户信息端点(https://api.linkedin.com/v2/userinfo)获取用户资料,替代旧版的/v2/me接口。
内容的提问来源于stack exchange,提问作者Vlad Forfutdinov
相关产品推荐
相关产品推荐

