What I am trying to accomplish:
LISessionManager sessionManager = LISessionManager.getInstance(getApplicationContext());
LISession session = sessionManager.getSession();
boolean accessTokenValid = session.isValid();
String respon ="";
if(accessTokenValid) {
String url = "https://api.linkedin.com/v1/people/~?format=json";
//String url = "https://api.linkedin.com/v1/people/~:(id,first-name,last-name,picture-url)";
APIHelper apiHelper = APIHelper.getInstance(getApplicationContext());
apiHelper.getRequest("your activity", url, new ApiListener() {
@Override
public void onApiSuccess(ApiResponse apiResponse) {
respon = apiResponse.toString();
Log.e("Response ", respon);
}
@Override
public void onApiError(LIApiError LIApiError) {
Log.e("error", LIApiError.toString());
}
});
}
As noted in LinkedIn's Android SDK authentication documentation (https://developer.linkedin.com/docs/android-sdk-auth),
Mobile vs. server-side access tokens
It is important to note that access tokens that are acquired via the Mobile SDK are only useable with the Mobile SDK, and cannot be used to make server-side REST API calls.
Similarly, access tokens that you already have stored from your users that authenticated using a server-side REST API call will not work with the Mobile SDK.
While LinkedIn states that it is not possible to use an access token provided by the Mobile SDK to make server-side API calls, I was able to make such calls just by adding x-li-src: msdk
in the header of the request.