Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LinkedIn access token is null when using Android SDK

  public void signInWithLinkedIn(View view){
        LISessionManager.getInstance(getApplicationContext()).init(this, buildScope(), new AuthListener() {
            @Override
            public void onAuthSuccess() {

                Toast.makeText(getApplicationContext(), "success" + LISessionManager.getInstance(getApplicationContext()).getSession().getAccessToken().getValue(), Toast.LENGTH_LONG).show();
                Log.d("SESSION", Boolean.toString(LISessionManager.getInstance(getApplicationContext()).getSession().isValid()));
                //fetchBasicProfileData();
            }

            @Override
            public void onAuthError(LIAuthError error) {

                Toast.makeText(getApplicationContext(), "failed " + error.toString(),
                        Toast.LENGTH_LONG).show();
            }
        }, true);

        // After complete authentication start new HomePage Activity
    }

The block of code in onAuthSuccess got executed but getSession returns null AND most importantly the access token is null, making me unable to call other linkedin APIs. This happens only recently. Am I doing it correctly?

Updated:- One more thing it generally happens with few specific LinkedIn Ids and working fine with rest of the id.

like image 506
kylas Avatar asked Jan 16 '19 17:01

kylas


People also ask

How to integrate LinkedIn API in Android app?

Implementing LinkedIn API in Android app helps users to login using LinkedIn account, share post, etc. For integrating the LinkedIn API in our Android app, we need the LinkedIn Authentication Key (Client ID and Client Secret) and app Hash Key. 1.

How to create a LinkedIn authentication key using LinkedIn API?

Fill all the required details of Android application in 'Create a New Application' form and accept the LinkedIn API Terms of Use then click 'Submit'. 3. After submitting the application details, it generates LinkedIn Authentication Key.

Why is my API access token invalid?

An access token could be invalid because it has expired or was revoked. When you integrate with the API, it is important to code your application to properly handle 401 Unauthorized errors. For example, if you receive the error, you can use the client ID and client secret to generate a new access token and retry your request.

Why am I getting a 401 Unauthorized error with LinkedIn Learning API?

If you call the LinkedIn Learning API with an invalid access token, you will receive a 401 Unauthorized error. An access token could be invalid because it has expired or was revoked. When you integrate with the API, it is important to code your application to properly handle 401 Unauthorized errors.


1 Answers

LinkedIn is updating its android sdk and they deprecate several methods.They started doing this from this week, I also got the same problem.You should use javascript api's to authenticate user rather than using linkedin android sdk.We fixed ur problem the same way.

like image 192
Asad Ali Avatar answered Sep 29 '22 03:09

Asad Ali