You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Supabase LinkedIn OAuth获取用户的LinkedIn经历与教育信息?

解决方案:通过Supabase OAuth获取LinkedIn用户的经历与教育信息

1. 配置LinkedIn OAuth权限范围

Supabase默认的LinkedIn OAuth仅请求基础权限(如r_liteprofile、r_emailaddress),无法获取经历/教育信息。你需要补充对应权限:

  • 进入Supabase控制台的 Authentication > Providers > LinkedIn,在「Scopes」字段添加r_fullprofile r_emailaddress(旧版API),或新版API的member:read:profile member:read:email。
  • 同步在LinkedIn开发者后台,进入「产品 > 权限与功能」,添加并启用上述权限;若应用面向公众,需提交LinkedIn审核。

2. 从Supabase会话提取LinkedIn访问令牌

Supabase的登录会话中包含LinkedIn的访问令牌,存放在session.provider_token字段,可通过以下方式获取:

import { createClient } from '@supabase/supabase-js'

const supabase = createClient('你的Supabase URL', '你的匿名密钥')

// 发起LinkedIn OAuth登录
await supabase.auth.signInWithOAuth({
  provider: 'linkedin',
  options: {
    scopes: 'r_fullprofile r_emailaddress' // 匹配配置的权限
  }
})

// 监听登录状态,提取令牌
supabase.auth.onAuthStateChange((event, session) => {
  if (event === 'SIGNED_IN' && session) {
    const linkedinToken = session.provider_token
    // 用该令牌调用LinkedIn API
  }
})

3. 调用LinkedIn API获取经历与教育数据

拿到linkedinToken后,直接调用LinkedIn REST API获取对应数据:

async function fetchLinkedInUserInfo(token) {
  // 获取教育经历
  const educationResp = await fetch(
    'https://api.linkedin.com/v2/educations?q=member&projection=(elements*(schoolName,degreeName,startDate,endDate))',
    { headers: { 'Authorization': `Bearer ${token}` } }
  )
  const educationData = await educationResp.json()

  // 获取工作经历
  const experienceResp = await fetch(
    'https://api.linkedin.com/v2/positions?q=member&projection=(elements*(companyName,title,startDate,endDate))',
    { headers: { 'Authorization': `Bearer ${token}` } }
  )
  const experienceData = await experienceResp.json()

  return {
    education: educationData.elements || [],
    experience: experienceData.elements || []
  }
}

4. 关键注意事项

  • 权限审核:面向公众的应用,r_fullprofile等敏感权限需通过LinkedIn审核,测试阶段可使用开发者账号的测试用户。
  • 令牌有效期:LinkedIn访问令牌有时间限制,过期后可通过Supabase的refresh token重新获取,或引导用户重新登录。
  • 权限最小化:仅请求必要权限,避免过度申请,提升审核通过率。

内容的提问来源于stack exchange,提问作者bsaoptima

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 20:07:37