linkIn与Android App集成的问题

时间:2015-07-29 16:27:26

标签: android linkedin

我正在开发一个Android应用程序,我想使用linkedIn signIn。 我跟着tuto Oauth 2.0 authorization for LinkedIn in Android ... 我获得了访问令牌,但我无法找到获取Profile Data的下一步的方法.PLease可以帮助我!

1 个答案:

答案 0 :(得分:0)

Android Mobile SDK

LinkedIn API Documentation

使用官方LinkedIn android 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);
    }
  

您可以使用以下代码段

发布到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);