Unable to logout from linkedin using javascript api

心已入冬 提交于 2019-12-18 09:23:32

问题


I have a piece of code to log user out from linkedin and its not working :(

any help will be greatly appreciated.


Logout code


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

try {
    IN.User.logout();
} catch (err) {
    console.log(err);
}
setTimeout("goToHome()", 10000);

function goToHome() {
    location.href="index.php";
}
</script>
</head>
</html>

console log


TypeError
arguments: Array[2]
get message: function () { [native code] }
get stack: function () { [native code] }
set message: function () { [native code] }
set stack: function () { [native code] }
type: "non_object_property_call"
__proto__: Error

Best regards, Pawan


回答1:


It looks like you are trying to call IN.User.logout() before the LinkedIn JavaScript platform has completely loaded. You should run the code only once you are sure the library is loaded, via either the onLoad value in the platform bootstrap section:

<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);
  }
  setTimeout("goToHome()", 10000);
}

function goToHome() {
  location.href="index.php";
}
</script>

Alternatively, use one of the event callbacks:

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

<script type="text/javascript">
IN.Event.onOnce(IN, 'systemReady', function() {
  try {
    IN.User.logout();
  } catch (err) {
    console.log(err);
  }
  setTimeout("goToHome()", 10000);
});

function goToHome() {
  location.href="index.php";
}
</script>


来源:https://stackoverflow.com/questions/12489017/unable-to-logout-from-linkedin-using-javascript-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!