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
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.
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.
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 :
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.
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);
}
Try Log to ensure whether function is called.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With