Reputation:
I am trying to get LinkedIn Access Token after login. Login is working fine with JavaScript SDK and I'm able to receive "oauth_token" and member_id. I need access_token to verify the email address (if it is not forged on the way).
Below is my script:
<script>
function LoginWithLinkedIn() {
IN.User.authorize(afterAuthorization);
}
function afterAuthorization(response){
debugger
if(IN.User.isAuthorized()==true){
getProfileData();
}
}
function onSuccess(data) {
console.log(data);
}
function onError(error) {
console.log(error);
}
function getProfileData(r) {
IN.API.Profile("me")
.fields("id,firstName,lastName,email-address,picture-urls::(original),public-profile-url,location:(name)")
.result(onSuccess)
.error(onError);
}
</script>
I need help getting the access_token after successful authorization. Any help is highly appreciated!
Thanks!
Upvotes: 4
Views: 903
Reputation: 2138
Hope following code will work
function LinkedInLogin() {
IN.User.authorize(getProfileData);
}
function onSuccess(data) {
jQuery('#hdnAccessToken').val(IN.ENV.auth.oauth_token);
try {
jQuery('#hdnSocialLoginType').val('in');
jQuery('#HiddenFieldUserId').val(data.values[0].id);
jQuery('#HiddenFieldEmail').val(data.values[0].emailAddress);
jQuery('#HiddenFieldFirstName').val(data.values[0].firstName);
jQuery('#HiddenFieldLastName').val(data.values[0].lastName);
jQuery('#HiddenFieldType').val('linkedin');
jQuery('#BtnLoginSocial').click();
}
catch (err) {
alert(jQuery('#HiddenErrorMessage').val());
}
//console.log(data);
}
function onError(error) {
console.log(error);
}
function getProfileData() {
if (IN.User.isAuthorized() == true) {
IN.API.Profile("me").fields("id,firstName,lastName,email-address").result(onSuccess).error(onError);
}
}
Upvotes: 2