【问题标题】:Issue with linkedIn integration with Android AppLinkedIn 与 Android 应用程序集成的问题
【发布时间】:2015-10-20 18:27:00
【问题描述】:

我正在开发一个安卓应用程序,我想使用linkedIn 登录。 我跟着tuto Oauth 2.0 authorization for LinkedIn in Android... 我得到了访问令牌,但我找不到下一步获取个人资料数据的方法。请你帮帮我!

【问题讨论】:

    标签: android linkedin


    【解决方案1】:

    Android Mobile SDK

    LinkedIn API Documentation

    使用官方LinkedInandroid mobile sdk。以下代码将为您完成使用android mobile sdk获取详细信息的工作

    Constants.java

            public static final String HOST = "api.linkedin.com";
            public static final String FETCH_BASIC_INFO = "https://" + HOST + "/v1/people/~:(id,first-name,last-name,headline,location,industry)";
            public static final String FETCH_CONTACT_INFO = "https://" + HOST + "/v1/people/~:(num-connections,email-address,phone-numbers,main-address)";
            public static final String FETCH_PROFILE_PICTURE = "https://" + HOST + "/v1/people/~:(picture-urls::(original))";
            public static final String SHARE_POST = "https://" + HOST + "/v1/people/~/shares";
    

    登录成功后可以如下调用API

    APIHelper apiHelper = APIHelper.getInstance(MainActivity.this);
    
            apiHelper.getRequest(MainActivity.this, Constants.FETCH_BASIC_INFO, new ApiListener() {
                @Override
                public void onApiSuccess(ApiResponse s) {
    
                        String response = apiResponse.toString()
    
    
    
                }
    
                @Override
                public void onApiError(LIApiError error) {
    
                   String errorCode= error.toString()
    
    
                }
            });
    

    不要忘记设置客户端权限

    /*Set LinkedIn permission for fetch info */
        private static Scope buildScope() {
            return Scope.build(Scope.R_BASICPROFILE, Scope.W_SHARE, Scope.R_EMAILADDRESS, Scope.R_CONTACTINFO);
        }
    

    您可以使用以下 sn-p 在 LinkedIn 上发帖

    public void postRequest(String shareUrl, String shareJsonText) {
            APIHelper apiHelper = APIHelper.getInstance(context);
            apiHelper.postRequest(activity, shareUrl, shareJsonText, new ApiListener() {
                @Override
                public void onApiSuccess(ApiResponse apiResponse) {
                    String response = apiResponse.toString()
    
                }
    
                @Override
                public void onApiError(LIApiError error) {
                     String errorCode= error.toString()
                }
            });
        }
    

    调用方法

    String shareJsonText = "{ \n" +
                            "   \"comment\":\"" + shareComment.getText() + " About our company : Codelynks is a provider of software solutions provider for leading companies round the globe. Codelynks is exclusively into helping the clients manage the ..." + "\"," +
                            "   \"visibility\":{ " +
                            "      \"code\":\"anyone\"" +
                            "   }," +
                            "   \"content\":{ " +
                            "      \"title\":\"Test Share Title\"," +
                            "      \"description\":\"Codelynks - Inspired Innovations\"," +
                            "      \"submitted-url\":\"http://www.codelynks.com/\"," +
                            "      \"submitted-image-url\":\"http://m3.licdn.com/media/p/3/000/124/1a6/089a29a.png\"" +
                            "   }" +
                            "}";
    
    
          postRequest(Constants.SHARE_POST, shareJsonText);
    

    【讨论】:

      最近更新 更多