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_HEREis 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: trueflag 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 registerhttp://localhost:portexplicitly), this can fail silently or throw cryptic errors. - Fix script loading issues: The protocol-relative URL
//platform.linkedin.com/in.jswon’t work if you’re testing locally viafile://(opening the HTML file directly in your browser). Spin up a simple local server (likepython -m http.serverornpx serve) to test overhttp://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
getProfileDatafunction 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
相关产品推荐
相关产品推荐

