Search code examples
javascriptweb-serviceslinkedin-api

Linked-in Javascript SDK : IN is undefined


I am trying to use the Linked-in Javascript SDK to add their sharing functionality on a site I'm working on. I have included this code in the <head> section of my page, as per the documentation:

<script type="text/javascript" src="//platform.linkedin.com/in.js">
api_key:   "API_KEY"
onLoad:    ""
authorize: true
lang:      "en_US"
</script>

After that, in the body of my page, I make the below call:

IN.API.Raw('/people/~/shares').method('POST').body(bodyContent).result(function(){});

However, I get the following error in chrome: Uncaught ReferenceError: IN is not defined.

Anybody has any idea what could be the cause of this error and how to fix it?


Solution

  • I finally found the problem: I was adding the SDK-initializing script to the <head> element using innerHTML. Apparently, that didn't seem like a good idea, from the error logged in the chrome console. All I had to do was directly put the script within the <head> element and that resolved the IN is not defined error.