我正在构建一个Android应用程序,用户将使用linkedin登录。
[当用户单击按钮时,当我单击“接受”时,输入电子邮件ID和密码后,将显示默认的Linkedin登录页面,我将禁用获取用户详细信息。
下面是我的登录代码-
public void onClick(View v) {
if (v.getId() == R.id.btnLinkedin) {
oAuthService = LinkedInOAuthServiceFactory.getInstance()
.createLinkedInOAuthService(Constants.CONSUMER_KEY,
Constants.CONSUMER_SECRET);
System.out.println("oAuthService : " + oAuthService);
factory = LinkedInApiClientFactory.newInstance(
Constants.CONSUMER_KEY, Constants.CONSUMER_SECRET);
liToken = oAuthService
.getOAuthRequestToken(Constants.OAUTH_CALLBACK_URL);
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(liToken
.getAuthorizationUrl()));
Toast.makeText(getApplicationContext(), "3", Toast.LENGTH_LONG).show();
startActivity(i);
}
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Toast.makeText(getApplicationContext(), "", Toast.LENGTH_LONG).show();
try {
linkedInImport(intent);
} catch (NullPointerException e) {
e.printStackTrace();
}
}
private void linkedInImport(Intent intent) {
String verifier = intent.getData().getQueryParameter("oauth_verifier");
System.out.println("liToken " + liToken);
System.out.println("verifier " + verifier);
LinkedInAccessToken accessToken = oAuthService.getOAuthAccessToken(
liToken, verifier);
client = factory.createLinkedInApiClient(accessToken);
// client.postNetworkUpdate("LinkedIn Android app test");
Person profile = client.getProfileForCurrentUser(EnumSet.of(
ProfileField.ID, ProfileField.FIRST_NAME,
ProfileField.LAST_NAME, ProfileField.HEADLINE));
System.out.println("First Name :: " + profile.getFirstName());
System.out.println("Last Name :: " + profile.getLastName());
System.out.println("Head Line :: " + profile.getHeadline());
}
LinkedIn现在提供了一个Android开发SDK,可以更轻松地为您处理这些情况,您可能需要研究一下:
我知道这是一个旧主题,但是以防万一有人来这里寻找答案...
LinkedIn已根据this link弃用并停止支持其旧的移动SDK,因此我为Android创建了轻量级的“非官方” SDK,您可以从this GitHub repo中使用它。
我们还在生产应用程序中使用了它,因此它应该可以正常工作。 :)