问题
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