我在项目中实现了Linkedin登录,并且运行良好。但是一周前突然停止工作,并显示一条错误消息,未能获取基本配置文件数据。其他一些Android开发人员也面临相同的问题,iOS开发人员也正在发生这种情况。调试后发现,我得到的“ AccessToken”值等于null。
这是我的onClick方法,称为onAuthSuccess方法。
binding.framelayoutLinkedin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
LISessionManager.getInstance(getApplicationContext()).init(LoginActivity.this, buildScope()
, new AuthListener() {
@Override
public void onAuthSuccess() {
fetchBasicProfileData();
}
@Override
public void onAuthError(LIAuthError error) {
Toast.makeText(context, "Failed to authenticate with LinkedIn. Please try again.", Toast.LENGTH_SHORT).show();
}
}, true);
}
});
onActivityResult
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
LISessionManager.getInstance(getApplicationContext()).onActivityResult(this, requestCode, resultCode, data);
}
buildScope
private static Scope buildScope() {
return Scope.build(Scope.R_BASICPROFILE, Scope.R_EMAILADDRESS, Scope.W_SHARE);
}
这是每当我尝试获取数据时都会在此onApiError中调用的fetchBasicProfileData方法。
private void fetchBasicProfileData() {
String url = "https://api.linkedin.com/v1/people/~:(id,first-name,last-name,headline,public-profile-url,picture-url,email-address,picture-urls::(original))";
APIHelper apiHelper = APIHelper.getInstance(getApplicationContext());
apiHelper.getRequest(this, url, new ApiListener() {
@Override
public void onApiSuccess(com.linkedin.platform.listeners.ApiResponse apiResponse) {
progressDialog.show();
getFirebaseTokenId();
try {
JSONObject jsonObject = apiResponse.getResponseDataAsJson();
String fullName = jsonObject.getString("firstName") + " " + jsonObject.getString("lastName");
getLoginLinkedIn(jsonObject.getString("id"), fullName,
userToken, jsonObject.getString("emailAddress"), "1",
jsonObject.getString("pictureUrl"));
// Toast.makeText(context, jsonObject.getString("pictureUrl"), Toast.LENGTH_SHORT).show();
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onApiError(LIApiError liApiError) {
Log.e("", "Fetch profile Error :" + liApiError.getLocalizedMessage());
Toast.makeText(context, "Failed to fetch basic profile data. Please try again.", Toast.LENGTH_SHORT).show();
}
});
}