Android Linkedin SDK 1.0.0 Example
In a previous post, I have explained how to access the Linkedin API's using Scribe. But luckily Linkedin have introduced their Mobile SDK for Android recently. This will save lot of times for developers and hope in the future will have lot of functions over the SDK.
In this post I'm going to give some hints and important steps to integrate Linkedin SDK for existing linkedin integrated(Using Scribe) application. When using Scribe for OAuth authentication, linkein returned us an AccessToken and we saved that in shared preferences for future use. With the new SDK we can use the previously saved AccessToken to access linkein API's without creating new token. I have added that example in SDKIntergrationActivity.java class and it's being commented. You can refer this project and previous project in Github.(Find the below code snippet in SDKIntergrationActivity.java)
There are few important points that should keep in mind while integrating new SDK.
1) Keep different keystore files for different build types. Specially authorization will fail if we use debug.keystore for release build type. It will give the below error for authentication fail.
2) Generate the KEY HASH and add the PACKAGE NAME in to https://www.linkedin.com/secure/developer > Application Details > Android Package Names and Hashes. The format of the content as below and one application can support multiple packages and different build types. Each PACKAGE NAME and KEY HASH should start in a new line.
Linkedin SDK is currently using the volley library for network operations. I have faced a limitation with volley implementation, where I tried to get User Connections list and it returned me SSL handshake exception. Find more info in here.
To Overcome this exception I had to customize the volley library, by setting the setSSLSocketFactory in HttpsURLConnection class. You can find the changes in com.android.volley.toolbox.Volley class line 72.
I have uploaded source to Github.
In this post I'm going to give some hints and important steps to integrate Linkedin SDK for existing linkedin integrated(Using Scribe) application. When using Scribe for OAuth authentication, linkein returned us an AccessToken and we saved that in shared preferences for future use. With the new SDK we can use the previously saved AccessToken to access linkein API's without creating new token. I have added that example in SDKIntergrationActivity.java class and it's being commented. You can refer this project and previous project in Github.(Find the below code snippet in SDKIntergrationActivity.java)
LocalSharedPreferenceStorage localSharedPreferenceStorage = LocalSharedPreferenceStorage.getInstance(context); Token prevToken = localSharedPreferenceStorage.getLinkedinAccessToken(); if(prevToken != null){ AccessToken token = AccessToken.buildAccessToken(prevToken.getToken()); liSessionManager.init(token); }
There are few important points that should keep in mind while integrating new SDK.
1) Keep different keystore files for different build types. Specially authorization will fail if we use debug.keystore for release build type. It will give the below error for authentication fail.
Error={"errorMessage": "either bundle id or package name \/ hash are invalid, unknown, malformed", "errorCode": "UNKNOWN_ERROR"}
2) Generate the KEY HASH and add the PACKAGE NAME in to https://www.linkedin.com/secure/developer > Application Details > Android Package Names and Hashes. The format of the content as below and one application can support multiple packages and different build types. Each PACKAGE NAME and KEY HASH should start in a new line.
PACKAGE_NAME_ONE,KEY_HASH_ONE PACKAGE_NAME_TWO,KEY_HASH_TWO PACKAGE_NAME_THREE,KEY_HASH_THREE
Linkedin SDK is currently using the volley library for network operations. I have faced a limitation with volley implementation, where I tried to get User Connections list and it returned me SSL handshake exception. Find more info in here.
javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0x6304aff0: Failure in SSL library, usually a protocol error error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure (external/openssl/ssl/s23_clnt.c:741 0x5e0c9fec:0x00000000)
To Overcome this exception I had to customize the volley library, by setting the setSSLSocketFactory in HttpsURLConnection class. You can find the changes in com.android.volley.toolbox.Volley class line 72.
I have uploaded source to Github.
Comments
allprojects {
repositories {
mavenCentral()
}
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.myapp.hello"
minSdkVersion 14
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
signingConfigs {
sdkTest {
storeFile file("secureln.jks")
storePassword "password"
keyAlias "secureln"
keyPassword "password"
}
release {
storeFile file("secureln.jks")
storePassword "password"
keyAlias "secureln"
keyPassword "password"
}
}
buildTypes {
sdkTest {
debuggable false
signingConfig signingConfigs.sdkTest
}
release {
debuggable false
signingConfig signingConfigs.release
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
compile project(':linkedin-sdk')
}
configurations {
}
dependencies {
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.google.code.gson:gson:2.3.1'
}
my gradle file look like this.and i pasted the .jks file inside app direction
http://developer.android.com/tools/publishing/app-signing.html#signing-manually
In your build.gradle file for signingConfigs use storeFile file("secureln.keystore") instead of storeFile file("secureln.jks")
Read this for more info
http://developer.android.com/tools/publishing/app-signing.html#release-mode
If you got any questions just ask.
Is it SSL error or "UNKNOWN_ERROR"??
I added Package_name and Hash_value in the url but ,still i am getting below error
Error={
"errorCode": "INVALID_REQUEST",
"errorMessage": "the request scope is invalid, unknown, malformed"
}