Features | Installation | Usage | API | Contribution
In order to use all of the ti.linkedin module features, the official LinkedIn app must be installed on the device.
This module:
- Authenticates with your Linkedin account
- Gets information about the logged user after login phase
- Opens a specific user profile page
- Supports a generic authenticated request
A few steps must be done to properly configure the LinkedIn SDK for both Android and iOS platforms.
First of all create an application. If you have an existing LinkedIn application, configure it on the Developer website.
If you've already done these steps jump to the Usage section.
Go to the "Mobile" setting page, and configure your application Bundle ID value in your LinkedIn application settings.
Now, pick the Application Id and write the following code inside your tiapp.xml under the <ios>
section:
<key>LIAppId</key>
<string>{Your LinkedIn Application ID}</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>li{Your LinkedIn Application ID}</string>
</array>
</dict>
</array>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>linkedin.com</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
</dict>
</dict>
If you are targeting your application also for iOS 9 devices add this further code:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>linkedin</string>
<string>linkedin-sdk2</string>
<string>linkedin-sdk</string>
</array>
Like for iOS, you have to do some setup steps to make this module working on Android platform.
First of all, generate a SHA1 hash for your certificate:
keytool -exportcert -alias yourkeystorealias -keystore /your/keystore/path/yourapp.keystore | openssl sha1 -binary | openssl base64
In a development scenario, you can use a development keystore shipped with the Titanium SDK:
keytool -exportcert -alias tidev -keystore ~/Library/Application\ Support/Titanium/mobilesdk/osx/7.1.0.GA/android/dev_keystore | openssl sha1 -binary | openssl base64
Go to the "Mobile" setting page and, under the Android section, add your application package and the SHA1 generated in the previous step.
Pick the latest version of the module and unzip it inside your application module folder or install it automatically via gitt.io
gittio install ti.linkedin
Check if in your application's tiapp.xml the ti.linkedin module is declared as follows:
<modules>
<module platform="iphone">ti.linkein</module>
<module platform="android">ti.linkedin</module>
</modules>
and you're ready to use it.
The module was developed to have a parity with the ti.facebook module developed by Appcelerator.
Before to start the login phase, call the initialize
method. After that you can call the authorize
one. You will be redirected to the LinkedIn official application.
When the user tap on the Accept button, your app will comes to foreground and the login
event will be fired with the user data as payload.
Here is a short login example:
var linkedin = require('ti.linkedin');
linkedin.addEventListener('login', onLogin);
linkedin.addEventListener('logout', onLogout);
linkedin.initialize();
linkedin.authorize();
function onLogin(event) {
Ti.API.info('User logged in?', event.success);
Ti.API.info(JSON.stringify(event));
if (!event.success) {
return;
}
// Do other stuff with event.data
}
function onLogout(event) {
Ti.API.info('User logged out.');
}
Do you want a more complete example? Look a the sample app.js.
After a successful authorize, you can get a valid oauth access token via linkedin.accessToken
property.
As per the docs you can't forward and use this client token from your backend:
It is important to note that access tokens that are acquired via the Mobile SDK are only usable with the Mobile SDK, and cannot be used to make server-side REST API calls.
Similarly, access tokens that you already have stored from your users that authenticated using a server-side REST API call will not work with the Mobile SDK.
But there is an easy way to do this.
Before to start a REST API call, simply set your request headers to:
"Authorization": "Bearer <YOUR_ACCESS_TOKEN>"
"x-li-src": "msdk"
and you will get a valid response.
initialize
initialize the moduleauthorize
starts the authorization phase opening the official LinkedIn application and ask the user if it wants to allow your application to fetch its profile data. It will fire alogin
eventlogout
clears the current LinkedIn session and will fire alogout
event.
login
an event that is fired after an authorization attempt with these sub-propertiessuccess
Indicates if the user was logged in successfully. Returnstrue
if request succeeded,false
otherwiseerror
Error message, if any returned. Will be undefined if success istrue
code
Error code will be undefined ifsuccess
istrue
, a specific error code otherwiseuid
User ID returned by LinkedIn if the login was successfuldata
Data returned by LinkedIn when we query for the current logged user profile after a successful login. Data is in JSON format, and includes information such as name, surname and profile picture.
logout
Fired at session logout.
accessToken
OAuth token set after a successful authorizeloggedIn
Indicates if the user is logged inpermissions
Array of permissions to request for your app. Be sure the permissions you want are set before calling authorize.
Here are all permissions you can use to authorize your app. For a complete description about the fields you can obtain using a specific permission have a look here.
PERMISSION_BASIC_PROFILE
for name, photo, headline and current user positionPERMISSION_COMPLETE_PROFILE
for full user profile including experience, education, skills and recommendationsPERMISSION_COMPANY_PERMISSION
for managing user company page and post updatesPERMISSION_EMAIL_ADDRESSES
for user email addressPERMISSION_CONTACT_INFO
for user contact infoPERMISSION_SHARE
to post updates, make comments and like directly from your app
Creating code takes time. We love to share our work to you because we believe in open source. This does mean however that we also have to spend time working contracts to pay the bills. This is where you can help: by chipping in you can ensure more time is spent improving this and other modules rather than dealing with distractions.
So please feel free to make a PR!
We promise they will be reviewed in a short time period and merged asap.