Skip to content
This repository has been archived by the owner on Mar 14, 2019. It is now read-only.

Cordova plugin for LinkedIn

License

Notifications You must be signed in to change notification settings

zyra/cordova-plugin-linkedin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DEPRECATION NOTICE

This repository will not be maintained anymore due to LinkedIn announcement that terminates their mobile SDK support. Read more here: https://engineering.linkedin.com/blog/2018/12/developer-program-updates

==========

npm npm npm

Cordova LinkedIn Plugin

A Cordova plugin that lets you use LinkedIn Native SDKs for Android and iOS.

Installation

  1. Create a LinkedIn app here
  2. Click on your app's name, then select the Mobile page from the side menu
  3. Add package name and hash for Android
  4. Copy the Application Id in the iOS section and use it in the installation command below
cordova plugin add cordova-plugin-linkedin --variable APP_ID=YOUR_APP_ID

Usage

login

login(scopes, promptToInstall, success, error)
  • scopes: Scopes to authenticate with
  • promptToInstall: If set to true, the user will be prompted to install the LinkedIn app if it's not already installed Logs the user in with selected scopes. Available scopes are: r_basicprofile, r_emailaddress, rw_company_admin and w_share.

logout

logout()

A synchronous method that clears the existing session.

getRequest

getRequest(path, success, error)
  • path: The request path Makes a GET request to LinkedIn REST API. You can view the possible paths here.

postRequest

postRequest(path, body, success, error)
  • path: The request path
  • body: The reqeust body Makes a POST request to LinkedIn REST API. You can view the possible paths here.

openProfile

openProfile(memberId, success, error)
  • memberId: Member Id of the user Opens a member's profile in the LinkedIn app.

hasActiveSession

hasActiveSession(success, error)

- - - DEPRECATED - - - This method is deprecated and will be removed in the next major release. Please use getActiveSession instead.

Checks if there is already an existing active session. This should be used to avoid unnecessary login.

The success callback function will be called with one argument as a boolean, indicating whether there is an active session.

getActiveSession

getActiveSession(success, error)

Checks if there is an existing active session.

The success callback function will be called with an object containing the access token and expiry date (if they exist).

Example

// generic callback functions to make this example simpler
var onError = function(e) { console.error('LinkedIn Error: ', e); }
var onSuccesss = function(r) { console.log('LinkedIn Response: ', r); }

// logging in with all scopes
// you should just ask for what you need
var scopes = ['r_basicprofile', 'r_emailaddress', 'rw_company_admin', 'w_share'];

// login before doing anything
// this is needed, unless if we just logged in recently
cordova.plugins.LinkedIn.login(scopes, true, function() {

  // get connections
  cordova.plugins.LinkedIn.getRequest('people/~', onSuccess, onError);
  
  // share something on profile
  // see more info at https://developer.linkedin.com/docs/share-on-linkedin
  var payload = {
    comment: 'Hello world!',
    visibility: {
      code: 'anyone'
    }
  };
  cordova.plugins.LinkedIn.postRequest('~/shares', payload, onSuccess, onError);

}, onError);


// check for existing session
cordova.plugins.LinkedIn.getActiveSession(function(session) {
  if (session) {
    console.log('We have an active session');
    console.log('Access token is: ', session.accessToken);
    console.log('Expires on: ', session.expiresOn);
  } else {
    console.log('There is no active session, we need to call the login method');
  }
});



Contribution

  • Having an issue? or looking for support? Open an issue and we will get you the help you need.
  • Got a new feature or a bug fix? Fork the repo, make your changes, and submit a pull request.

Support this project

If you find this project useful, please star the repo to let people know that it's reliable. Also, share it with friends and colleagues that might find this useful as well. Thank you 😄