Unofficial SDK for LinkedIn v2 REST APIs
- Sign In with LinkedIn
- Fetch LinkedIn user full profile (id , firstName , lastName , profilePicture , emailAddress)
1- Create app on LinkedIn Developers Console
2- From Auth section get Client ID and Client Secret and do not forget to add “Redirect URL”. The reason being, it will be later used to get callback for identifying the response in native webviews. You can put in any Redirect URL and not necessarily a real one. It can be any value starting with https:// prefix. For example Redirect Url
https://com.kromer.linkedin.oauth/oauth
3- Add in your root build.gradle at the end of repositories
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
4- Add the dependency in your app build.gradle file
dependencies {
implementation 'com.github.kerolloskromer:linkedin-sdk:<latest-version>'
}
5- Sign in with LinkedIn with single line
Linkedin.signIn(MainActivity.this, clientId, clientSecret, redirectURL, state);
"state" is a unique string of your choice designed to protect against CSRF attacks.
6- Receive sign in response
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == Linkedin.REQ_CODE_SIGN_IN) {
if (resultCode == Linkedin.SUCCESS) {
LinkedinUser linkedinUser = data.getParcelableExtra(Linkedin.USER);
Toast.makeText(MainActivity.this, linkedinUser.getFirstName(), Toast.LENGTH_SHORT).show();
} else if (resultCode == Linkedin.FAILURE) {
int errorType = data.getIntExtra(Linkedin.ERROR_TYPE, 0);
switch (errorType) {
case Linkedin.ERROR_NO_INTERNET:
Toast.makeText(MainActivity.this, "Please check your internet connection",
Toast.LENGTH_SHORT).show();
break;
case Linkedin.ERROR_USER_CANCELLED:
Toast.makeText(MainActivity.this, "User cancelled authorization", Toast.LENGTH_SHORT)
.show();
break;
case Linkedin.ERROR_OTHER:
Toast.makeText(MainActivity.this, "Something went wrong", Toast.LENGTH_SHORT).show();
break;
}
}
}
}
Please feel free to report bug , issue or improvement - see the Issues section fisrt to prevent duplicates. Also, if you know how to fix this issue please feel free to fork this repo and make a pull request and i will gladly review and merge and add you as a contributer :)
- Mina Mikhail - Android Developer - LinkedIn - Github
- Esraa Nayel - Android Developer - LinkedIn - Github
- Share on LinkedIn
This project is licensed under the MIT License - see the LICENSE file for details