I am developing an android app and i want to use the linkedIn signIn. I have followed the tuto Oauth 2.0 authorization for LinkedIn in Android... I get the access token but i can't find a way to the next step to get Profile Data.PLease can u help me!
Asked
Active
Viewed 337 times
1 Answers
0
Use official LinkedIn android mobile sdk
.following codes will do the job for you for fetching detalis by using android mobile sdk
Constants.java
public static final String HOST = "api.linkedin.com";
public static final String FETCH_BASIC_INFO = "https://" + HOST + "/v1/people/~:(id,first-name,last-name,headline,location,industry)";
public static final String FETCH_CONTACT_INFO = "https://" + HOST + "/v1/people/~:(num-connections,email-address,phone-numbers,main-address)";
public static final String FETCH_PROFILE_PICTURE = "https://" + HOST + "/v1/people/~:(picture-urls::(original))";
public static final String SHARE_POST = "https://" + HOST + "/v1/people/~/shares";
You can call the API's as follows after successfull login
APIHelper apiHelper = APIHelper.getInstance(MainActivity.this);
apiHelper.getRequest(MainActivity.this, Constants.FETCH_BASIC_INFO, new ApiListener() {
@Override
public void onApiSuccess(ApiResponse s) {
String response = apiResponse.toString()
}
@Override
public void onApiError(LIApiError error) {
String errorCode= error.toString()
}
});
Do not forget to set client side permissions
/*Set LinkedIn permission for fetch info */
private static Scope buildScope() {
return Scope.build(Scope.R_BASICPROFILE, Scope.W_SHARE, Scope.R_EMAILADDRESS, Scope.R_CONTACTINFO);
}
You can post to LinkedIn using following snippet
public void postRequest(String shareUrl, String shareJsonText) {
APIHelper apiHelper = APIHelper.getInstance(context);
apiHelper.postRequest(activity, shareUrl, shareJsonText, new ApiListener() {
@Override
public void onApiSuccess(ApiResponse apiResponse) {
String response = apiResponse.toString()
}
@Override
public void onApiError(LIApiError error) {
String errorCode= error.toString()
}
});
}
Call the method
String shareJsonText = "{ \n" +
" \"comment\":\"" + shareComment.getText() + " About our company : Codelynks is a provider of software solutions provider for leading companies round the globe. Codelynks is exclusively into helping the clients manage the ..." + "\"," +
" \"visibility\":{ " +
" \"code\":\"anyone\"" +
" }," +
" \"content\":{ " +
" \"title\":\"Test Share Title\"," +
" \"description\":\"Codelynks - Inspired Innovations\"," +
" \"submitted-url\":\"http://www.codelynks.com/\"," +
" \"submitted-image-url\":\"http://m3.licdn.com/media/p/3/000/124/1a6/089a29a.png\"" +
" }" +
"}";
postRequest(Constants.SHARE_POST, shareJsonText);

Anoop M Maddasseri
- 10,213
- 3
- 52
- 73