Logout from LinkedIn API

I have worked with LinkedIn API and need guidance about logging out from Linkedin API once I click Logout in my application. I have tried the following code:

function closeSession(){
    IN.User.logout();
}
<a href="logout.php" class="myButton" onclick="closeSession()" id="logout-link">Logout In LinkedIn</a>

I have also tried:

$('logout-link').click(function() {  
    IN.Event.on(IN,'logout', function() {
        window.location.href = [site-logout-url];
    });
    IN.User.logout();
});

I tried to destroy the session in a browser by calling session_destroy()

Finally, I tried the answer I got from Stack Overflow for this question. I didn't get any right solution. Can anyone tell me the solution?

Answers:

Answer

Make sure that you have include

<script type="text/javascript" src="http://platform.linkedin.com/in.js"></script>  

on your home page, i.e. where you are logging out.

Answer

Seems your onclick is not being called, try doing:

function closeSession(){
   IN.User.logout();
   return true;
}
<a href="logout.php" class="myButton" onclick="return closeSession();" id="logout-link">Logout In LinkedIn</a>

OR

<a href="#" class="myButton" onclick="closeSession()" id="logout-link">
    Logout In LinkedIn
</a>

And js

function closeSession() {
  if ( typeof IN === 'object' && typeof IN.User === 'object' && IN.User.isAuthorized() ) {
     //user logged in linkedin
    //call linkedin logout with websites logout function as callback
     alert("I m inside linkedin object check.."); //do you see this
     IN.User.logout(logout);
  }
  else {
     logout();
  }
}
function logout() {
  window.location.href = "URL_TO_YOUR_LOGOUT.PHP";
}
Answer

I think you are redirected before your javascript gets executed, so try this way ? JavaScript Code :

function closeSession(){
    IN.User.logout();
    location.href="logout.php";
}

HTML Code :

<span style="cursor:pointer" onclick="closeSession()">Logout In LinkedIn</span>
Answer
To make it work



<script type="text/javascript" src="http://platform.linkedin.com/in.js">
api_key: <?php echo sfConfig::get('app_linkedin_api_key'); ?>
authorize: true
</script>
<script>
IN.Event.on(IN, "logout", function() {onLinkedInLogout();});

function onLinkedInLogout(){
// User is logged out
window.location.href='<?php echo url_for("@homepage");?>'
}
</script>
<a href="#" onclick="IN.User.logout()"><?php echo __("Logout");?></a>

<div class="signin"><script type="in/Login" data-onAuth="onLinkedInAuth"></script>

<script type="text/javascript">

function onLinkedInAuth() {
IN.API.Profile("me")
.fields("id")
.result( function(me) {
var id = me.values[0].id;
//Do stuff like redirect...
})
}
</script>
Answer

There seems to be 2 different issues here. You can't logout of linked in from your server side script unless you call their function. When you land on logout.php you should have your session_destroy(); on top of the page. Make sure there isn't any session_start() on logout.php

Answer

You need to load the LinkedIn JavaScript platform before trying to call IN.User.logout(), you should run the code only after the javascript library has loaded completely.

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

<script type="text/javascript">
function onLoad() {
  try {
    IN.User.logout();
  } catch (err) {
    console.log(err);
  }
  location.href="index.php";
}
</script>
Answer
<script type="text/javascript" src="http://platform.linkedin.com/in.js">
api_key: mykey
authorize: true
onLoad: onLoad
</script>

           <script type="text/javascript">
                 function onLoad() {
                  try {
              IN.User.logout();
                       } catch (err) {
                  console.log(err);
                          }
                  location.href="index.php";
                    }
                     </script>
Answer

use session_destroy() in the code.

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.