24

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?

Community
  • 1
  • 1
MUTHURAJ
  • 261
  • 2
  • 8
  • [Reffered this?](http://developer.linkedin.com/documents/inauth-inevent-and-inui) – Pankit Kapadia Dec 18 '12 at 06:34
  • I can see that your DOM query is not correct and basically it's not able to attach the onclick event. You need to add a hash # when you're querying a DOM element by id: $('#logout-link').click(...) – Omid Monshizadeh Nov 01 '14 at 15:17

8 Answers8

1

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.

Pankit Kapadia
  • 1,579
  • 13
  • 25
Sridhar
  • 2,228
  • 10
  • 48
  • 79
0

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";
}
Sudhir Bastakoti
  • 99,167
  • 15
  • 158
  • 162
  • I have checked that by placing alert(); into that method ,Alert was displayed . – MUTHURAJ Dec 18 '12 at 04:23
  • @MUTHURAJ see the edited code, try alert()'ing inside if condition of isAuthorized() in the code to see if the IN object actually exist and user is actually authorized with linkedin, hope that works – Sudhir Bastakoti Dec 18 '12 at 04:27
0

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>
Dexter
  • 12,172
  • 9
  • 27
  • 30
  • tell me what happend, does the first line of function executed or not, is the page redirected to `logout.php` – Dexter Dec 18 '12 at 04:49
0
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>
Suresh Sekar
  • 928
  • 6
  • 7
0

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

unixmiah
  • 3,081
  • 1
  • 12
  • 26
0

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>
0
<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>
m.usman
  • 43
  • 7
-3

use session_destroy() in the code.

Rakesh
  • 9
  • 7