Android LinkedIn SDK produces unusable access tokens

前端 未结 3 873
青春惊慌失措
青春惊慌失措 2020-12-11 17:45

What I am trying to accomplish:

  • Authenticate w/ LinkedIn via their Android SDK
  • Fetch User\'s profile to obtain their userId
  • Create new user a
相关标签:
3条回答
  • 2020-12-11 18:33
    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());
            }
        });
    }
    
    0 讨论(0)
  • 2020-12-11 18:36

    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.

    0 讨论(0)
  • 2020-12-11 18:36

    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.

    0 讨论(0)
提交回复
热议问题