Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LinkedIn Login with basic example not working

I would like to add the possibility of LinkedIn login to my project. I followed the tutorial given on the LinkedIn developer page and ended up with the following code, really basic stuff from that tutorial:

<!-- linkedin login -->
<script type="text/javascript" src="//platform.linkedin.com/in.js">
  api_key:   [MY_API_KEY] {~n}
  authorize: false {~n}
  onLoad: onLinkedInLoad {~n}
</script>

<!-- linkedin login play -->
<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>

Don't mind the {~n} as I'm using dust.js to render the page and I need them to pass the arguments to the LinkedIn script.

So, the login button appears, this means that LinkedIn was able to connect to my API key correctly, but the Chrome console gives me the following error: Uncaught Error: Could not execute 'onLinkedInLoad'. Please provide a valid function for callback.. Since this is the example given on the tutorial page, I don't know what can be wrong with it. Even if I declare the block of LinkedIn login functions before the call to the LinkedIn in.js, I get the same error.

I think it is a very easy mistake to spot, but I cannot really tell what am I doing wrong.

like image 636
Masiar Avatar asked Dec 06 '15 11:12

Masiar


1 Answers

This is happening cause you are calling onLinkedInLoad() in head section,and if you are working on multiple pages..it will be called on the every page even if it doesn't have data from API call(or simply you are not making any call on the page where this error is appearing).

Try this`

// Removing event listener by calling IN.Event.on() outside of 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);
}

` And Yes remove " onLoad: onLinkedInLoad {~n}" from first script call

like image 143
Bhawna Jain Avatar answered Oct 20 '22 08:10

Bhawna Jain