Monday, 25 April 2016

LinkedIn Integration - Andorid

Introduction

LinkedIn is one of the most popular social networking platforms available today. LinkedIn users can share status updates, respond to topics of interest, read the latest updates from contacts and companies, and participate in group discussions about topics that interest them.

The popularity of social networking platforms like Facebook, LinkedIn, and Twitter means that mobile app developers are tightly integrating these services with their applications to allow users to share content on these sites without ever leaving an application.

Overview of SDK

  • The mobile SDK for Android increases your app's time to market by providing out-of-box support for LinkedIn natively inside your Android applications.
  • The Mobile SDK for Android requires the official LinkedIn Android application is also installed to support the SDK's capabilities.
  • The minimum supported version is Android 4.4.2 (API 19).

 

SDK Features

  • Single sign-on (SSO) authentication, in conjunction with the LinkedIn mobile app.
  • A convenient wrapper for making authenticated calls to LinkedIn's REST APIs.
  • "Deep linking" to additional member data in the LinkedIn mobile app.
  • Sample application that demonstrate best-practice implementations of all of the SDK's features.

Please find steps below for LinkedIn integration in Android.

 

Step - 1 Create Application  
  • To Integrate LinkedIn in your mobile application, you need to create a new application using LinkedIn Developer’s Account.
  • Create application from LinkedIn developer account.
    https://www.linkedin.com/developer/apps



Step - 2 Set the Application Permission
  • Now, you need to set  the Default Application Permissions.
    And to do that, you have to select check box “r_basicprofile” and “r_emailaddress” and click on the “update” button to set the permission.



Step - 3 Download Mobile LinkedIn SDK

Go to https://developer.linkedin.com/docs/android-sdk  and download a Mobile SDK for Android.


Step - 4 Generate Hash Key
  • We need to generate a hash key. This generated Hash key will integrate your app with Linkedin account.
  • Go to https://www.linkedin.com/developer/apps  
  • Select your application name and click the Mobile tab. 
  • Add the package name and generated hash key in your LinkedIn Application.
  • This hash key will authenticate your mobile application. 




Login

private static final String topCardUrl = "https://" + host + "/v1/people/~:(first-name,last-name,email-address,formatted-name,phone-numbers,public-profile-url,picture-url,picture-urls::(original))"
private static Scope buildScope() {
    return Scope.build(Scope.R_BASICPROFILE, Scope.R_EMAILADDRESS, Scope.W_SHARE);
}
public void loginLinkedin() {
LISessionManager.getInstance(getApplicationContext()).init(this,
   buildScope(), new AuthListener() {
         @Override 
         public void onAuthSuccess() {

           APIHelper apiHelper = APIHelper.getInstance(getApplicationContext());
           apiHelper.getRequest(MainActivity.this, topCardUrl, new ApiListener() {
                @Override                         
                public void onApiSuccess(ApiResponse s) {
                           
                 Log.e(TAG, "Profile json" + s.getResponseDataAsJson());
                 Log.e(TAG, "Profile String" + s.getResponseDataAsString());

                   try {
                     Log.e(TAG, "Profile emailAddress" + s.getResponseDataAsJson().get("emailAddress").toString());
                     Log.e(TAG, "Profile formattedName" + s.getResponseDataAsJson().get("formattedName").toString());

                     txtFirstName.setText(s.getResponseDataAsJson().get("emailAddress").toString());
                     txtLastName.setText(s.getResponseDataAsJson().get("formattedName").toString()); 
                     Picasso.with(MainActivity.this).load(s.getResponseDataAsJson().getString("pictureUrl"))
                            .into(imgProfilePic);

                        }catch (Exception e){

                        }

              }

                @Override 
                public void onApiError(LIApiError error) {
                            //((TextView) findViewById(R.id.response)).setText(error.toString());                            Toast.makeText(getApplicationContext(), "Profile failed " + error.toString(),
                                    Toast.LENGTH_LONG).show();
                        }
                    });

                }

         @Override                 
         public void onAuthError(LIAuthError error) {

         Toast.makeText(getApplicationContext(), "failed " + error.toString(),
                            Toast.LENGTH_LONG).show();
                }
            }, true);

Logout

LISessionManager.getInstance(getApplicationContext()).clearSession();

Check Login

private boolean isLogin(){
    LISessionManager sessionManager = LISessionManager.getInstance(getApplicationContext());
    LISession session = sessionManager.getSession();
    boolean accessTokenValid = session.isValid();
    return accessTokenValid;
}
Share Message
private static final String shareUrl = "https://" + host + "/v1/people/~/shares";
 
public void shareMessage() {
    APIHelper apiHelper = APIHelper.getInstance(getApplicationContext());
    apiHelper.postRequest(MainActivity.this, shareUrl, buildShareMessage("Hello World", "Hello Title", "Hello Descriptions", "http://ankitthakkar90.blogspot.in/", "http://1.bp.blogspot.com/-qffW4zPyThI/VkCSLongZbI/AAAAAAAAC88/oGxWnHRwzBk/s320/10333099_1408666882743423_2079696723_n.png"), new ApiListener() {
        @Override 
        public void onApiSuccess(ApiResponse apiResponse) {
            // ((TextView) findViewById(R.id.response)).setText(apiResponse.toString());            Toast.makeText(getApplicationContext(), "Share success:  " + apiResponse.toString(),
                    Toast.LENGTH_LONG).show();
            Log.e(TAG, "share success" + apiResponse.toString());
        }

        @Override         
        public void onApiError(LIApiError error) {
            //   ((TextView) findViewById(R.id.response)).setText(error.toString());            Toast.makeText(getApplicationContext(), "Share failed " + error.toString(),
                    Toast.LENGTH_LONG).show();
        }
    });
} 

public String buildShareMessage(String comment,String title,String descriptions,String linkUrl,String imageUrl  ){
    String shareJsonText = "{ \n" +
            "   \"comment\":\"" + comment + "\"," +
            "   \"visibility\":{ " +
            "      \"code\":\"anyone\"" +
            "   }," +
            "   \"content\":{ " +
            "      \"title\":\""+title+"\"," +
            "      \"description\":\""+descriptions+"\"," +
            "      \"submitted-url\":\""+linkUrl+"\"," +
            "      \"submitted-image-url\":\""+imageUrl+"\"" +
            "   }" +
            "}";
    return shareJsonText;
}
Open Current User Profile
public void openUserProfile(){
    DeepLinkHelper deepLinkHelper = DeepLinkHelper.getInstance();
    deepLinkHelper.openCurrentProfile(MainActivity.this, new DeepLinkListener() {
        @Override         
        public void onDeepLinkSuccess() {
            Log.e(TAG, "openUserProfile success");
        }

        @Override 
        public void onDeepLinkError(LIDeepLinkError error) {
            Log.e(TAG, "openUserProfile error" + error.toString());
        }
    });
}

Best Practices

Posting on member's behalf
  •  Members assume that they will have control on what content is posted and shared on their behalf. You should assure users that you will not post or send mail on their behalf without their consent, and give them the option to edit content before it is posted or not share content if they choose.

Permission Request
  • You should educate users on which permissions you are requesting and how this data will be used. LinkedIn does not support incremental permission request, so all permissions must be granted during the authorization step.  
  •  Requesting too many permissions may cause users not to authorize your application, so you should only ask for the permissions that you need.
Authentication
  • Whenever possible, remind the user that they are logged into your application by displaying their name, portrait, and/or account settings.
  • You should also avoid multiple log in prompts. 
  • Cache the user's access token after they grant your application and do not bring the user through the authentication flow again unless they log out or the access token expires or is otherwise invalid.
  • You should allow the user to log out, and when they do log out you should destroy the access token you had been granted.

 

Cancelling in-progress requests

During your application's workflow, you may wish to cancel any in-progress API requests.  This is done by calling APIHelper.cancelCalls() method.

Using ProGaurd with your application 

If you intend to use ProGuard on the release build of your mobile application, you will need to add the following lines to your project's proguard-project.txt file to preserve information required for the SDK to function properly:

proguard configuration

-keep class com.linkedin.** { *; }
-keepattributes Signature

Mobile vs. server-side access tokens            

It is important to note that access tokens that are acquired via the Mobile SDK are only useable with the Mobile SDK, and cannot be used to make server-side REST API calls.

Similarly, access tokens that you already have stored from your users that authenticated using a server-side REST API call will not work with the Mobile SDK.

Partnership Program

  • All other APIs (e.g. Connections, Groups, People Search, Invitation, Job Search, etc.) will require developers to become a member of one of our partnership programs.  
  • Partnering with LinkedIn provides you with additional API functionality & data access, increased call limits & dedicated support.
  • Applications are only accepted when we feel that they're providing value to members, developers and LinkedIn.
https://developer.linkedin.com/partner-programs

References

https://developer.linkedin.com/docs/android-sdk
https://developer.linkedin.com/docs/android-sdk-auth
https://developer.linkedin.com/downloads#androidsdk
https://www.numetriclabz.com/android-linkedin-integration-login-tutorial/
https://developer.linkedin.com/docs/oauth2
https://developer.linkedin.com/partner-programs/apply
https://developer.linkedin.com/support/developer-program-transition
http://www.solutionanalysts.com/blog/step-by-step-developers-guide-to-integrate-linkedin-with-an-android-application/

You can Download source code of this example from Github.



68 comments:


  1. Your thinking toward the respective issue is awesome also the idea behind the blog is very interesting which would bring a new evolution in respective field. thanks for sharing.

    Android Training in Chennai

    ReplyDelete
  2. I think this is most application of issues in contents post.So try to issues correct post.


    Java training in Chennai

    ReplyDelete
  3. I read this content really awesome.You provided another one great article.I hope this information may change my business carrier.I can remember these things whenever taking the decision.


    php training in Chennai

    ReplyDelete
  4. the blog is very useful, interesting and informative. thank you for sharing the blog with us. keep on updating.

    Software Testing Training in Chennai

    ReplyDelete
  5. Thank you for sharing the information here. Its much informative and really i got some valid information. You had posted the amazing article.

    Hadoop Training in Chennai

    ReplyDelete
  6. This is a great post. I like this topic.This site has lots of advantage.I found many interesting things from this site. It helps me in many ways.Thanks for posting this again.

    Java Training in Chennai

    ReplyDelete

  7. It is really very excellent,i find all articles was amazing.awesome way to get exert tips from everyone,
    not only i like that post all peoples like that post,because of all given information was wonderful and it's very helpful for me.
    Java training in Chennai

    ReplyDelete
  8. Thanks share this program and step by steps contents are very useful to my knowledge.

    hadoop

    ReplyDelete
  9. Thanks for sharing as it is an excellent post would love to read your future post for more knowledge- I was in search of such blog who explore my knowledge in the industry.for more knowledge. android development company India & Canada

    ReplyDelete

  10. Usually I do not read post on blogs, but I would like to say that this write-up very forced me to try and do it! Your writing style has been surprised me. Thanks, very nice article.

    Digital marketing company in Chennai

    ReplyDelete
  11. Good post. I learn something totally new and challenging on blogs I stumble upon on a daily basis. It will always be interesting to read articles from other authors and practice something from their websites...

    Digital marketing company in Chennai

    ReplyDelete
  12. Thanks for sharing this list. Very grateful. I work at mobile app testing company where i think it will be definitely useful.


    Software Development Company in Chennai

    ReplyDelete
  13. Great information provided about Android Training . I appreciate your work.

    ReplyDelete
  14. This is a great post. I like this topic.This site has lots of advantage.I found many interesting things from this site. It helps me in many ways.Thanks for posting this again. website designing company canada

    ReplyDelete
  15. this blog is nice and interesting too thanks for sharing those information it is really well and good.

    Best Android Training Institute in Chennai

    ReplyDelete
  16. This comment has been removed by the author.

    ReplyDelete
  17. Your information is really helpful for application development.
    Custom eCommerce Solution Providers

    ReplyDelete
  18. When LISessionManager.init() is called, the LinkedIn application will immediately return the user back to the specified Android Activity within your application. your Information is really appreciable its helps in Mobile Apps Development

    ReplyDelete
  19. Hi, I wanted to ask if is there any way that during likedin login , we can avoid linkedin startscreen that appears before the login page

    ReplyDelete
  20. Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing
    dot net training in chennai
    php training in chennai
    java training in chennai

    ReplyDelete
  21. Thanks for sharing such a great information..Its really nice and informative.
    PHP Training in Chennai

    ReplyDelete
  22. I am very much pleased with the contents you have mentioned. I wanted to thank you for this great article. I enjoyed every little bit part of it and I will be waiting for the new updates.

    Android app developer

    ReplyDelete
  23. Hey nice work! I really appreciate your article and your effort made.. Technology Company in Chennai

    ReplyDelete
  24. This article is very much helpful and i hope this will be an useful information for the needed one. Keep on updating these kinds of informative things...
    Mobile App Development Company
    Android app Development Company
    ios app development Company
    Mobile App Development Companies

    ReplyDelete
  25. Wow, these are good news since we will be able to access our LinkedIn profiles via the mobile phones thus facilitating more connectivity and socialization. I will be downloading the application soon and installing it on my mobile phone. I hope the writer will continually keep us updated with similar information. Check out our writing website by clicking on Help with Qualitative Dissertation Analysis Chapter.

    ReplyDelete
  26. I have read your blog its very attractive and impressive. I like it your blog.

    Java Training in Chennai Core Java Training in Chennai Core Java Training in Chennai

    Java Online Training Java Online Training JavaEE Training in Chennai Java EE Training in Chennai

    ReplyDelete
  27. Thanks for sharing this information. That is really impressive about android app development.

    Mobile app development services in USA
    Best mobile app development company

    ReplyDelete
  28. Thanks for posting useful information.You have provided an nice article, Thank you very much for this one. And i hope this will be useful for many people.. and i am waiting for your next post keep on updating these kinds of knowledgeable things...Really it was an awesome article...very interesting to read..please sharing like this information......
    Android training in chennai
    Ios training in chennai

    ReplyDelete
  29. I am expecting more interesting topics from you. And this was nice content and definitely it will be useful for many people.
    Mobile App Development Company
    Mobile App Development Companies

    ReplyDelete
  30. You have provided an nice article, Thank you very much for this one. And i hope this will be useful for many people.. and i am waiting for your next post keep on updating these kinds of knowledgeable things...
    Android App Development Company

    ReplyDelete

  31. Very informative ..i suggest this blog to my friends..Thank you for sharing Information...

    Android ios App Developers in India

    Android applications taking off high in the market, it may very well appear a piece of cake to the layman as to an Android Application Development Company in India.

    ReplyDelete
  32. well blog Vendorzapp provides Mobile apps for small business, Ecommerce android apps India, iOS ecommerce apps, Ecommerce website Pune, Ready ecommerce website and apps. Android ecommerce apps then visit now Ecommerce android apps India, iOS ecommerce apps, ecommerce website for small business call us +91-9850889625

    ReplyDelete
  33. I just see the post i am so happy to the communication science post of information's.So I have really enjoyed and reading your blogs for these posts.Any way I’ll be replay for your great thinks and I hope you post again soon...
    Java Training in Chennai

    ReplyDelete
  34. Thanks for the valuable information and insights you have so provided here...
    sell used cellphones

    ReplyDelete
  35. The blog gave me idea to SDK and The information about the way of integration with the android was very much useful My sincere thanks for sharing this post
    Android Training in Chennai

    ReplyDelete
  36. good blog Vendorzapp provides Mobile apps for small business, Ecommerce android apps India, iOS ecommerce apps, Ecommerce website Pune, Ready ecommerce website and apps. Android ecommerce apps then visit now Ecommerce android apps India, iOS ecommerce apps, ecommerce website for small business call us +91-9850889625

    ReplyDelete
  37. Thanks for given the features of lkdn and Android. Thanks for sharing the nice information about android. Any one want to learn Android Training in chennai.


    Android Training in Chennai

    ReplyDelete
  38. This is one of the beautiful article. I interest to rear again and again. Keep sharing more article like this. Thanks for sharing..


    Android Training in Chennai

    ReplyDelete
  39. Nice blog.. Thanks for sharing informative blog.. I just want to say that all the information you have given here is awesome...great and nice blog thanks sharing. Android development company

    ReplyDelete
  40. Interesting blog which attracted me more.Spend a worthful time.keep updating more.
    MSBI Training in Chennai

    ReplyDelete
  41. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    Android Training in Chennai
    Ios Training in Chennai

    ReplyDelete
  42. This article is very much helpful and i hope this will be an useful information for the needed one.Keep on updating these kinds of informative things...
    iOS App Development Company
    Android App Development Company
    Best Mobile app Development company
    Android App Development Company in chennai
    iOS App Development Company in chennai

    ReplyDelete
  43. I wondered upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon.
    http://smarther.co/ios-app-development-company/
    http://smarther.co/android-app-development-company/

    ReplyDelete
  44. I wondered upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon.
    iOS App Development Company
    Android App Development Company

    ReplyDelete
  45. I think like I get a clear cut understanding while reading the content than anywhere else. Keep continuing this journey...!

    Pawn Shops in Montgomery

    Pawn Shops in Birmingham

    Pawn Shops in Mobile

    ReplyDelete
  46. Being new to the blogging world I feel like there is still so much to learn. Your tips helped to clarify a few things for me as well as giving..
    Sms marketing
    Text message marketing
    Fitness SMS

    ReplyDelete
  47. Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing..
    Sms marketing
    Text message marketing
    Fitness SMS

    ReplyDelete
  48. This comment has been removed by the author.

    ReplyDelete
  49. Hey!!! There Very Nice And Impressive Blog. Its so Helpfull
    Please Visit our website for more details
    Linkedin Advertisement/

    ReplyDelete