Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LinkedIn Authentication not working on Fragment in android

I am creating an app that has the LinkedIn login. I am following this documentation. But when I click on the login button, the app redirected to the LinkedIn app and asking for login. When successful login it redirected to my app. But nothing happens. Nothing happens on onActivityResult also. Below is my code .Login implemented on fragment

 LISessionManager.getInstance(getActivity()).init(getActivity(), buildScope(), new AuthListener() {
            @Override
            public void onAuthSuccess() {
                getLinkedInProfile();
                Toast.makeText(getApplicationContext(), "success" , Toast.LENGTH_LONG).show();
            }
            @Override
            public void onAuthError(LIAuthError error) {
                Toast.makeText(getApplicationContext(), "failed " + error.toString(), Toast.LENGTH_LONG).show();
            }
        }, true);

//

private static Scope buildScope() {
    return Scope.build(Scope.R_BASICPROFILE, Scope.R_EMAILADDRESS);
}

and onActivityResult as follows:

     @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        LISessionManager.getInstance(getActivity()).onActivityResult(getActivity(), requestCode, resultCode, data);
}

Already added hash and package name on LinkedIn developer console. Did I am missing anything? Please help

like image 482
Vinayak B Avatar asked Sep 05 '17 18:09

Vinayak B


People also ask

How do I authenticate to LinkedIn using a mobile authenticator?

Click on LinkedIn in the mobile authenticator app to show an authentication code. Enter the 6-digit code on the LinkedIn website and click Continue. Multifactor authentication is turned on. We can also add Phone Number (SMS) as multifactor authentication, but unfortunately we can’t add both methods at the same time.

Is it possible to set up LinkedIn authorization on Android?

Even though there is no such android specific sdk from linkedIn (like facebook and twitter sdk for android).Setting up linkedIn authorization with Oauth 1.0 was still easy using: Social-auth for android. And the list of tools here. But its not the same story for authorization with Oauth2.0.

How to integrate LinkedIn API with Android app?

First, you need to have your LinkedIn API Key and Secret Key. If you don't, register an app on here. Second, you need an Activity in the application that can receive the authorization code. For that, it needs to be set as browsable (launchable from a browser) in the AndroidManifest.xml file :

How do I add LinkedIn as an account to the app?

This adds LinkedIn as an account to the app. Click on LinkedIn in the mobile authenticator app to show an authentication code. Enter the 6-digit code on the LinkedIn website and click Continue. Multifactor authentication is turned on.


2 Answers

It is found that the onActivityResult for LinkedIn sdk triggres on the parent activity rather than fragment onActivityResult. So you have to write following code into your parent Activity's onActivityResult for triggering fragment's onActivityResult.

 @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    yourFragment.onActivityResult(requestCode, resultCode, data);
}
like image 181
Vinayak B Avatar answered Nov 14 '22 22:11

Vinayak B


Try Log to ensure whether function is called.

like image 32
Arul Avatar answered Nov 15 '22 00:11

Arul