简体   繁体   English

如何在android中登录linkedin?

[英]How to Login linkedin in android?

I am building an android application where user will login using linkedin.我正在构建一个 android 应用程序,用户将在其中使用linkedin 登录。

When user click on the button the default linkedin login page appear after entering the Email ID and password when I click accepted I an disable to get user details.当用户单击按钮时,在输入电子邮件 ID 和密码后会出现默认的linkedin 登录页面,当我单击接受时,我将禁用获取用户详细信息。

Below is my login code -以下是我的登录代码 -

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 now provides an Android development SDK to handle these situations for you more easily, that you might want to look into: LinkedIn 现在提供了一个 Android 开发 SDK 来为您更轻松地处理这些情况,您可能想研究一下:

https://developer.linkedin.com/docs/android-sdk https://developer.linkedin.com/docs/android-sdk

I know this is an old thread, but just in case anyone came here looking for answers...我知道这是一个旧线程,但以防万一有人来这里寻找答案......

LinkedIn has deprecated and stopped supporting their old mobile SDKs as per this link , so I've created a lightweight "unofficial" SDK for Android, you can use it from this GitHub repo .根据此链接,LinkedIn 已弃用并停止支持其旧的移动 SDK,因此我为 Android 创建了一个轻量级的“非官方”SDK,您可以从此GitHub 存储库中使用它。

We also use it in our production apps, so it should be working fine.我们也在我们的生产应用程序中使用它,所以它应该可以正常工作。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM