Abhinav Jain
Abhinav Jain

Reputation: 151

LinkedIn API sample implementation not working

I am trying to get this particular piece of code working. It works fine in the developer console, but fails when try it on my computer in a html file. It gives me a error in the pop up which says [object Object]. Could really use some help here. I don't know why is code entering into the error handler while it works fine in the developer console of LinkedIn.

Thanks!

<html>
<head>
<script type="text/javascript" src="http://platform.linkedin.com/in.js">
api_key: my_actual_key
authorize: false
credentials_cookie: true
credentials_cookie_crc: true
onLoad: onLinkedInLoad

</script>
</head>
<body>
<p>This example demonstrates the use of a login button to control what's displayed. It also demonstrates how to use the LinkedIn auth events in a user flow.</p>

<div id="loginbadge">
<p>Login badge renders here if the current user is authorized.</p>
</div>
<!-- NOTE: be sure to set onLoad: onLinkedInLoad -->
<script type="text/javascript">
function onLinkedInLoad() {
IN.Event.on(IN, "auth", function() {onLinkedInLogin();});
IN.Event.on(IN, "logout", function() {onLinkedInLogout();});
}

function onLinkedInLogout() {
setLoginBadge(false);
}

function onLinkedInLogin() {
// we pass field selectors as a single parameter (array of strings)
IN.API.Connections("me")
.fields(["id", "firstName", "lastName", "pictureUrl", "publicProfileUrl"])
.result(function(result) {
setLoginBadge(result.values[0]);
})
.error(function(err) {
alert(err);
});
}

function setLoginBadge(profile) {
if (!profile) {
profHTML = "<p>You are not logged in</p>";
}
else {
var pictureUrl = profile.pictureUrl || "http://static02.linkedin.com/scds/common/u/img/icon/icon_no_photo_80x80.png";
profHTML = "<p><a href=\"" + profile.publicProfileUrl + "\">";
profHTML = profHTML + "<img align=\"baseline\" src=\"" + pictureUrl + "\"></a>";
profHTML = profHTML + "&nbsp; Welcome <a href=\"" + profile.publicProfileUrl + "\">";
profHTML = profHTML + profile.firstName + " " + profile.lastName + "</a>! <a href=\"#\" onclick=\"IN.User.logout(); return false;\">logout</a></p>";
}
document.getElementById("loginbadge").innerHTML = profHTML;
}
</script>

<!-- need to be logged in to use; if not, offer a login button -->
<script type="IN/Login"></script>
</body>

</html>

Upvotes: 2

Views: 3001

Answers (1)

Martin F
Martin F

Reputation: 610

Try replacing

IN.API.Connections("me")

with

IN.API.Profile("me")

Upvotes: 1

Related Questions