【问题标题】:How to get LinkedIn Contacts or Friends List in Android?如何在 Android 中获取 LinkedIn 联系人或好友列表?
【发布时间】:2013-11-15 04:37:36
【问题描述】:

任何人都可以帮助我使用 LinkedIn APIlinkedin-j-android.jar 获取 LinkedIn 联系人或朋友或联系人列表。我能够获取所有当前用户个人资料信息,但不知道如何获取联系人或朋友列表。我在 SO 和 Google 上找到了很多,但还没有找到正确的解决方案。请有人帮我解决这个问题。为此我已经尝试过了。

ProgressDialog progressDialog = new ProgressDialog(this);
    LinkedinDialog d = new LinkedinDialog(this, progressDialog);
    d.show();

    // set call back listener to get oauth_verifier value
    d.setVerifierListener(new OnVerifyListener() {
        @Override
        public void onVerify(String verifier) {
            try {
                accessToken = LinkedinDialog.oAuthService
                        .getOAuthAccessToken(LinkedinDialog.liToken,
                                verifier);
                LinkedinDialog.factory.createLinkedInApiClient(accessToken);
                client = factory.createLinkedInApiClient(accessToken);
                // client.postNetworkUpdate("Testing by Mukesh!!! LinkedIn wall post from Android app");
                Loggger.i(TAG, "ln_access_token: " + accessToken.getToken());
                Loggger.i(TAG,
                        "ln_access_token: " + accessToken.getTokenSecret());
                com.google.code.linkedinapi.schema.Person profile = client
                        .getProfileForCurrentUser(EnumSet.of(
                                ProfileField.ID, ProfileField.FIRST_NAME,
                                ProfileField.LAST_NAME,
                                ProfileField.CONNECTIONS));
                linkedInID = profile.getId();

                Loggger.i(TAG, "PersonID : " + linkedInID);
                linkedInFirstName = profile.getFirstName();
                linkedInLastName = profile.getLastName();
                Connections = profile.getConnections();
                Log.e(TAG, "CONNECTION : " + Connections);

                List<Contact> contactList;
                contactList = (ArrayList<Contact>) getIntent()
                        .getSerializableExtra("contact");
                for (int i = 0; i < contactList.size(); i++) {
                    final Contact bean = contactList.get(i);
                    Log.d("Custom-UI",
                            "Display Name = " + bean.getDisplayName());
                    Log.d("Custom-UI",
                            "First Name = " + bean.getFirstName());
                    Log.d("Custom-UI", "Last Name = " + bean.getLastName());
                    Log.d("Custom-UI", "Contact ID = " + bean.getId());
                    Log.d("Custom-UI",
                            "Profile URL = " + bean.getProfileUrl());
                    Log.d("Custom-UI",
                            "Profile Image URL = "
                                    + bean.getProfileImageURL());
                    Log.d("Custom-UI", "Email = " + bean.getEmail());
                }

                Loggger.e(TAG, "connections  : " + Connections);
                Loggger.e(TAG, "linkedin firstname : " + linkedInFirstName);
                Loggger.e(TAG, "linkedin lastname : " + linkedInLastName);



            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

    // set progress dialog
    progressDialog.setMessage("Loading...");
    progressDialog.setCancelable(true);
    progressDialog.show();

【问题讨论】:

    标签: java android linkedin


    【解决方案1】:

    r_network 范围最近更改为仅限 LinkedIn 合作伙伴权限。您可以在此处申请加入他们的合作伙伴计划:

    https://developer.linkedin.com/partner-programs/apply

    【讨论】:

      【解决方案2】:

      1.参考这个链接:https://github.com/Hafiz-Waleed-Hussain/EasyLinkedInAndroid作为库

      2.在主要java布局中使用:

      _EasyLinkedIn = EasyLinkedIn.getInstance(this, "api key",
                      "secret key",
                      "https://github.com/Hafiz-Waleed-Hussain/EasyLinkedInAndroid",
                      "", "");
      
          _EasyLinkedIn.authorize(MainActivity.this, new Callback() {
      
              @Override
              public void onSucess(Object data) {
      
                  String fields = "id,first-name,headline";
      
                  _EasyLinkedIn.getUserInfo(this, this, fields);
      
                  String fields1 = "id";
      
                  String url = "https://api.linkedin.com/v1/people/~/connections:(id=Gcn6gB9aCj)?format=json&oauth2_access_token="
                          + EasyLinkedIn.getAccessToken();
                  _EasyLinkedIn.getConnections(this, this, fields1);
      
              }
      
              @Override
              public void onFailure() {
      
              }
          });  
      

      onDownloadingComplete() 方法使用日志打印对象参数

      【讨论】:

      • 您是否有在简单的 java 类中获取本机应用程序li​​nkedin 访问令牌的链接。还记得没有活动课吗??
      猜你喜欢
      • 1970-01-01
      • 2017-11-24
      • 2016-10-08
      • 2012-05-20
      • 1970-01-01
      • 2020-10-16
      • 1970-01-01
      • 2017-09-11
      • 2023-01-04
      相关资源
      最近更新 更多