Skip to content

Instantly share code, notes, and snippets.

@eestradalucero
Created April 6, 2018 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eestradalucero/248db762c72338a26ab82a76661b700f to your computer and use it in GitHub Desktop.
Save eestradalucero/248db762c72338a26ab82a76661b700f to your computer and use it in GitHub Desktop.
var myMethods = {
OnProfileError:function(error)
{
console.log(error);
SendMessage ('LinkedinJS', 'LoginError', JSON.stringify(error));
},
OnProfileSuccess:function(result)
{
console.log(JSON.stringify(result));
SendMessage ('LinkedinJS', 'LoginSuccess', JSON.stringify(result));
},
GetProfileInfo:function()
{
IN.API.Raw("/people/~:(id,location,first-name,last-name,maiden-name,picture-urls::(original),industry,positions:(title,is-current,company:(name)))")
.result(OnProfileSuccess)
.error(OnProfileError);
},
OpenPopupLoginWindow:function()
{
console.log("Called lib OpenPopUp");
document.onmouseup = function()
{
IN.User.authorize(GetProfileInfo);
document.onmouseup = null;
}
},
Login:function()
{
console.log("Called lib Login");
OpenPopupLoginWindow();
},
CheckUserLoggedInState:function()
{
SendMessage('LinkedinWeb', 'JS_LoggedInCallback', IN.User.isAuthorized().toString());
},
// Handle the successful return from the API call
OnShareSuccess:function(data)
{
SendMessage('LinkedinJS', 'ShareSuccess', JSON.stringify(data));
console.log(data);
},
// Handle an error response from the API call
OnShareError:function(error)
{
SendMessage ('LinkedinJS', 'ShareError', JSON.stringify(error));
console.log(error);
},
//Comparte en linkedin
ShareContent:function(shareJson)
{
if(!IN.User.isAuthorized())
{
console.log("user not logged in, logging in....");
IN.User.authorize( function() {ShareContent(shareJson)} );
}
else
{
console.log("User logged in, sharing content...");
IN.API.Raw("/people/~/shares?format=json")
.method("POST")
.body(shareJson)
.result(OnShareSuccess)
.error(OnShareError);
}
},
ShareContentXML:function(lcXML)
{
if(!IN.User.isAuthorized())
{
console.log("user not logged in, logging in....");
IN.User.authorize(function () { ShareContentXML(lcXML) });
}
else
{
console.log("User logged in, sharing content xml...");
IN.API.Raw("/people/~/shares")
.method("POST")
.body(lcXML)
.result(OnShareSuccess)
.error(OnShareError);
}
},
OpenTabLink:function(linkString)
{
document.onmouseup = function()
{
window.open(linkString);
document.onmouseup = null;
}
},
Logout:function()
{
IN.User.logout(OnLogoutComplete, null);
},
OnLogoutComplete:function(object)
{
SendMessage('LinkedinJS', 'LogoutComplete');
},
Share:function()
{
var payload =
{
"comment": "Check out developer.linkedin.com!",
"content": {
"title": "LinkedIn Developers Resources",
"description": "Leverage LinkedIn's APIs to maximize engagement",
"submitted-url": "https://developer.linkedin.com",
"submitted-image-url": "https://www.searchenginegenie.com/images/14-samplelogo.jpg"
},
"visibility": {
"code": "connections-only"
}
};
ShareContent(JSON.stringify(payload));
},
ShareXML:function()
{
var payload = "<share><comment>Check out developer.linkedin.com!</comment><content><title>LinkedIn Developer Resources</title><description>Leverage LinkedIn's APIs to maximize engagement</description><submitted-url>https://developer.linkedin.com</submitted-url><submitted-image-url>https://www.searchenginegenie.com/images/14-samplelogo.jpg</submitted-image-url></content><visibility><code>connections-only</code></visibility></share>";
ShareContentXML(payload);
}
};
mergeInto(LibraryManager.library, myMethods);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment