How to save LinkedIn Access Token in android?

749 views Asked by At

I am using linkedin-j library for authenication

I want to persist the LinkedIn Access token object.

LinkedInOAuthService oAuthService = LinkedInOAuthServiceFactory
    .getInstance()
    .createLinkedInOAuthService(
        LK_CONSUMER_KEY, LK_CONSUMER_SECRET
    );

//Need to persist this accessToken
LinkedInAccessToken accessToken = oAuthService
    .getOAuthAccessToken(liToken, oauthVerifier);
1

There are 1 answers

1
Joel Fernandes On

You can use SharedPreferences.

This is an example shown for Facebook. You can implement the same way for for LinkedIn.

When the user has logged in:

Editor editor = context.getSharedPreferences("facebook-session", 
                                             Context.MODE_PRIVATE).edit();
editor.putString("access_token", session.getAccessToken());
editor.putLong("expires_in", session.getAccessExpires());

When you app starts, in onCreate, restore the session if it exists:

SharedPreferences savedSession = context.getSharedPreferences
                                 ("facebook-session",Context.MODE_PRIVATE);
session.setAccessToken(savedSession.getString("access_token", null));
session.setAccessExpires(savedSession.getLong("expires_in", 0));

Source: https://developers.facebook.com/blog/post/640/