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

LinkedIn JavaScript SDK报错:Uncaught TypeError: Cannot read property 'apply' of undefined

Troubleshooting Persistent LinkedIn API Error with Default Example Code

Ugh, I feel your pain—there’s nothing more frustrating than hitting a wall even when you’re following the official docs to the letter. Let’s break down some common fixes that usually resolve this kind of stubborn issue:

  • Double-check your API key: Make sure YOUR_API_KEY_HERE is swapped out for your actual, valid key from the LinkedIn Developer Portal. Typos, using a sandbox key for a production app, or forgetting to enable the necessary API products for your key are super common culprits.
  • Validate OAuth settings: The authorize: true flag triggers the auth flow, but if your app’s redirect URIs in the developer portal don’t exactly match what’s configured (even for local testing, you need to register http://localhost:port explicitly), this can fail silently or throw cryptic errors.
  • Fix script loading issues: The protocol-relative URL //platform.linkedin.com/in.js won’t work if you’re testing locally via file:// (opening the HTML file directly in your browser). Spin up a simple local server (like python -m http.server or npx serve) to test over http:// instead.
  • Dig into browser console errors: Hit F12 to open dev tools and check the Console tab. LinkedIn’s API almost always logs specific error details here—things like missing scopes, rate limits, or app permission issues that won’t show up in your code directly.
  • Test in incognito mode: Browser extensions (like ad blockers or privacy tools) or cached auth sessions can mess with the LinkedIn auth flow. Testing in incognito rules out these external conflicts quickly.

Here’s a polished version of your code snippet with added error handling and notes to highlight critical spots:

<script type="text/javascript" src="//platform.linkedin.com/in.js">
  api_key: YOUR_VALID_API_KEY_HERE <!-- Replace this with your actual, verified API key -->
  authorize: true
  onLoad: onLinkedInLoad
</script>
<script type="text/javascript">
  // Setup auth event listener
  function onLinkedInLoad() {
    IN.Event.on(IN, "auth", getProfileData);
  }

  // Handle successful API response
  function onSuccess(data) {
    console.log("Loaded profile data:", data);
    // Add your custom logic to use the data here
  }

  // Fetch profile data with error handling
  function getProfileData() {
    IN.API.Raw("/people/~")
      .result(onSuccess)
      .error(function(error) {
        console.error("LinkedIn API Error:", error); // Log errors for debugging
      });
  }
</script>

Quick note: Your original snippet was missing the getProfileData function definition, which would definitely cause issues! Adding that and explicit error handling will help you pinpoint exactly what’s going wrong.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 08:36:59