I am making a website for the first time. I am sorry for any dumb question but I really have no background. However, I am trying to learn. I developed the website on Weebly (www.i2i.network) and I am trying to include a LinkedIn SignUp button through their API service to monitor the people who are using the website.
So far I copied and pasted what I have found on the LinkedIn SDK guide
<script type="in/Login"></script>
<script type="text/javascript" src="//platform.linkedin.com/in.js">
IN.User.logout(callbackFunction, callbackScope);
api_key: [API] //I put my API key here
authorize: true
onLoad: onLinkedInLoad
lang: [LANG_LOCALE]
</script>
<script type="text/javascript">
// Setup an event listener to make an API call once auth is complete
function onLinkedInLoad() {
IN.Event.on(IN, "auth", getProfileData);
}
// Handle the successful return from the API call
function onSuccess(data) {
console.log(data);
}
// Handle an error response from the API call
function onError(error) {
console.log(error);
}
// Use the API call wrapper to request the member's basic profile data
function getProfileData() {
IN.API.Raw("/people/~").result(onSuccess).error(onError);
}
</script>
The button appeared the first time and it opens the connection to my LinkedIn profile. That's exciting! :D (Geek)
At this point I still don't know if I retrieve any data from the LinkedIn API service and if "yes" how to manage them and possibly include them in Intercom.io.
As far as I understood I should receive from LinkedIn API the following:
{
"firstName": "Frodo",
"headline": "Jewelery Repossession in Middle Earth",
"id": "1R2RtA",
"lastName": "Baggins",
"siteStandardProfileRequest": {
"url": "https://www.linkedin.com/profile/view?id=…"
}
}
Do I actually receive the answer? How do I read it? How do I use it in the following Intercom.io script?
<script>
window.intercomSettings = {
app_id: "k9sz4pfb",
name: "Nikola Tesla", // Full name
email: "[email protected]", // Email address
created_at: 1312182000 // Signup date as a Unix timestamp
};
</script>
<script>(function(){var w=window;var ic=w.Intercom;if(typeof ic==="function"){ic('reattach_activator');ic('update',intercomSettings);}else{var d=document;var i=function(){i.c(arguments)};i.q=[];i.c=function(args){i.q.push(args)};w.Intercom=i;function l(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='https://widget.intercom.io/widget/k92zopfb';var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);}if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}}})()</script>
I know this might be a very basic question but I am starting from zero and I like to learn by practicing...
Furthermore, if you have any suggestion about website or tutorial where I could learn step-by-step it will be really appreciated.
Thank you for your help,
Giacomo
Double check the syntax but this should get you started.
// Use the API call wrapper to request the member's basic profile data
function getProfileData() {
var dataOutput =
// I added the callback event DONE. This assures the data method is called when the this API call is successful and complete.
var dataOutput = IN.API.Raw("/people/~").result(onSuccess).error(onError).done( {
if (dataOutput != null) {
DoSomethingWithYourData(dataOutput);
}
});
}
function DoSomethingWithYourData(dataOutput) {
console.log(dataOutput);
// Parse your data or assign it to a control. do whatever here.
}
And to answer your other question, you can add this to a JS script file and reference it on other pages, but you would have to keep any control IDs/class names added to this script file the same, so my tip would be to keep this file very generic so that it does not depend on anything else and only deals with working with LinkedIn's data.
I recommend these links for further reading so that you can expand on your code.