I have implemented LinkedIn sign-in functionality using linkedin-sdk in one of my application, which was working perfectly. Since last few days, I'm not able to proceed further with an error stating
access token is not set
which was not needed before.
With the update of version 2.0, the access token has been made compulsory and the details lacking in the developer account.
I have implemented the same in this way:
private static final String host = "api.linkedin.com";
private static final String url = "https://" + host + "/v1/people/~:(first-name,last-name,email-address,formatted-name,phone-numbers,public-profile-url,picture-url,picture-urls::(original))";
LISessionManager.getInstance(getContext())
.init(getActivity(), buildScope(), new AuthListener() {
@Override
public void onAuthSuccess() {
APIHelper apiHelper = APIHelper.getInstance(getContext());
apiHelper.getRequest(getContext(), url, new ApiListener() {
@Override
public void onApiSuccess(ApiResponse apiResponse) {
try {
//edt_linkedInURL.setText(apiResponse.getResponseDataAsJson().get("publicProfileUrl").toString());
Log.e("Response", apiResponse.getResponseDataAsJson().toString());
setLinkedInData(apiResponse.getResponseDataAsJson());
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onApiError(LIApiError LIApiError) {
Toast.makeText(getContext(), "Profile failed " + LIApiError.toString(), Toast.LENGTH_LONG).show();
}
});
/* Toast.makeText(getActivity(), "success" +
LISessionManager.getInstance(getActivity())
.getSession().getAccessToken().getValue(),
Toast.LENGTH_LONG).show();*/
}
@Override
public void onAuthError(LIAuthError error) {
try {
JSONObject object = new JSONObject(error.toString());
C.INSTANCE.showToast(getContext(), object.optString("errorMessage"));
} catch (Exception e) {
Toast.makeText(getContext(), "Failed to get data with LinkedIn", Toast.LENGTH_LONG).show();
}
}
}, true);
private static Scope buildScope() {
return Scope.build(Scope.R_BASICPROFILE, Scope.R_EMAILADDRESS, Scope.W_SHARE);
}
How can the access token be generated with details of how to integrate V2 / OAuth2.0 in app?