Skip to content

Instantly share code, notes, and snippets.

@pangeaware
Created March 30, 2016 23:58
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save pangeaware/bf82c82c807190f0ff28e90d46e5cd71 to your computer and use it in GitHub Desktop.
Save pangeaware/bf82c82c807190f0ff28e90d46e5cd71 to your computer and use it in GitHub Desktop.
React Component Implementing the Linkedin Javascript SDK
var React = require('react');
var LinkedinLogin = React.createClass({
componentDidMount: function() {
var liRoot = document.createElement('div');
liRoot.id = 'linkedin-root';
document.body.appendChild(liRoot);
(function(d, s, id) {
const element = d.getElementsByTagName(s)[0];
const ljs = element;
var js = element;
if (d.getElementById(id)) {
return; }
js = d.createElement(s);
js.id = id;
js.src = '//platform.linkedin.com/in.js';
js.text = 'api_key: [YOUR_API_KEY]';
ljs.parentNode.insertBefore(js, ljs);
}(document, 'script', 'linkedin-sdk'));
},
callbackFunction: function() {
IN.API.Profile("me").result(function(r) {
console.log(r);
});
},
handleClick: function(e) {
e.preventDefault();
IN.User.authorize(this.callbackFunction, '');
},
render: function() {
return (
< div >
< button onClick = { this.handleClick }
className = { "button social " + this.props.name.toLowerCase() + " " + this.props.visibility } > { this.props.text } < i className = { "fi-social-" + this.props.name.toLowerCase() }
/></button >
< /div>
);
}
});
module.exports = LinkedinLogin;
@yasirrose
Copy link

Awesome!!!.

@greeddiscient
Copy link

Hello, I get IN is not defined when I try to build my app

@javidjamae
Copy link

javidjamae commented Jul 30, 2017

@greeddiscient - Try changing it to window.IN

Also, don't forget to remove the brackets around [YOUR_API_KEY], and make sure to pass in the props: name, visibility, and text

@renanborgez
Copy link

Thank you for sharing it with us.

@iphonic
Copy link

iphonic commented Sep 12, 2017

Is there anything I need to import or, add to make it work?

@kjvenky
Copy link

kjvenky commented Dec 21, 2017

Thanks for sharing. Struggled for 2 days :(

@kjvenky
Copy link

kjvenky commented Dec 21, 2017

How to get the access token using this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment