将Linkedin V2.0 / OAuth2.0集成到Android应用中

时间:2019-01-22 11:21:16

标签: android oauth-2.0 linkedin linkedin-api

我已经在我的一个应用程序中使用linkedin-sdk实现了LinkedIn登录功能,该应用程序运行良好。从最近几天开始,我无法继续进行错误提示

  

未设置访问令牌

以前不需要。

随着版本2.0的更新,访问令牌已成为强制性的,开发者帐户中缺少详细信息。

Warning message from LinkedIn attached.

我已经通过这种方式实现了

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);

}

如何生成包含如何在应用程序中集成V2 / OAuth2.0的详细信息的访问令牌?

0 个答案:

没有答案