Android LinkedIn SDK produces unusable access tokens

孤街浪徒 提交于 2019-11-28 13:38:33

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.

mainak
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());
        }
    });
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!