business@innofied.com

US Toll-Free - +1 866 941 5117

Top
LinkedIn-Integration-in-iOS-Apps2

LinkedIn Integration in iOS Apps

LinkedIn is a social cum professional platform that provides opportunities for connecting to various personalities belonging to your professional areas and other areas too. Business apps or event related apps demand LinkedIn integration for gathering industrialists on a common platform to discuss issues related to market awareness. Such apps help bringing big market personalities close to common people so that they can get instant solution to their business hurdles. So, today we are going to discuss about LinkedIn integration in iOS apps in detail.

Getting the OAuth Starter Kit

Go to this OAuth Starter Kit link and download the OAuth Kit for LinkedIn.

 Setting up the project for LinkedIn Integration

Go to the LinkedIn Developers page for setting up your application. Click on Add New Application and start filling out all the details about your application. After filling the page out with all the information about your app click on the Save button.

Note: In the Scope field, checkmark only those fields against which information is required.

Note down the Consumer Key / API Key, Consumer Secret /Secret Key, OAuth 1.0a User Token and OAuth 1.0a User Secret as these would be required at the time of integration.

Configuring the Xcode Project for Integration

1. From the downloaded Starter Kit, unzip the source code and drag the three folder Categories, Crypto and OAuthStarterKit into the project.

2. Enlist all the keys you obtained from the project configuration page in LinkedIn to your Project.pch file so that it is accessible from everywhere. If you do not have .pch file (as per Xcode 6) then you may create one.

3. Now go to your ViewController.m file from where you would initiate LinkedIn integration. Add the following line at the very top:

#import "OAuthLoginView.h"

4. After that create a private property of your OAuthLoginView file in the ViewController.m.

OAuthLoginView *linkedInLoginView;

5. Next, go to the method from where the process will be initiated and add the following lines of code:

linkedInLoginView = [[OAuthLoginView alloc] init];
linkedInLoginView.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
[self presentViewController:linkedInLoginView animated:YES completion:nil];

6. Now run your code. As soon as you fire LinkedIn integration an alert will appear with title “OAuth Starter Kit” and message “You must add your API key and secret key. See the project file readme.txt”.

For overcoming this problem, you will need to go to file OAuthLoginView.m in the following method -(void)initLinkedInApiassign the APIKey and SecretKey along with the keys you enlisted in .pch file.

apikey = LinkedInApiKey;
secretkey = LinkedInSecretKey;

7. From here go to method -(void)viewDidAppear:(BOOL)animated and there you will be able to see an if condition. In that if condition, change the value from 64 to 14 for APIKey and for SecretKey change it from 64 to 16. Now run your code.

As soon as you fire LinkedIn integration, you will see a LinkedIn login view will appear with a set of authorized permissions. As soon as you login you will get a JSON of the profile of the logged in person.

Note : While you will run the project you might run into some ARC issues. For getting rid of them add follow these steps :

  • Go to Build Phases tab of project settings.
  • Click on the Compile Sources option and you will see a list of .m files.
  • Double click on these files and add “-fno-objc-arc
    • NSString+URLEncoding.m
    • OADataFetcher.m
    • OATokenManager.m
    • OAServiceTicket.m
    • OAToken.m
    • OAuthLoginView.m
    • OAProblem.m
    • JSONKit.m
    • OARequestParameter.m
    • OAMutableURLRequest.m
    • ProfileTabView.m
    • NSMutableURLRequest+Parameters.m
    • OAAttachment.m
    • OAConsumer.m
    • OACall.m
    • OAHMAC_SHA1SignatureProvider.m

If you want more information from LinkedIn profiles, you can view these LinkedIn Profile fields and add any field you want. There is only one condition, your app has to authorize permissions for accessing those fields. You can add profile fields in function -(void)testApiCall. In the function, you can add attributes to the URL for getting more information.

For Example : If you want person’s first name, last name, formatted name, address, email address, industry, profile URL, profile picture URL, network, skills, phone number, company, position, education, activities; then your URL will look somewhat like this

  NSURL *url = [NSURL URLWithString:@"https://api.linkedin.com/v1/people/~:(id,first-name,last-name,maiden-name,formatted-name,email-address,location:(name),industry,public-profile-url,picture-url,primary-twitter-account,network,skills,summary,phone-numbers,date-of-birth,main-address,positions:(title,company:(name)),educations:(school-name,field-of-study,start-date,end-date,degree,activities))"];

You can modify URL according to your requirement.

You can download the sample project from GitHub.

This is it. Hope it helps. Feel free to comment if you face any problem while integrating LinkedIn. Any suggestion for improvement will be appreciated.

Manish Kumar

Manish Kumar is an iOS developer at Kolkata, who enjoys building innovative applications. Besides he also loves playing football and listening to songs. He loves challenges and sharing his work in open source community. Lots of iOS objective C development work is going on in Innofied. You can reach us at contact@innofied.com

  • Abhi Kumar

    I wish to implement sharing images and videos on linkedin for iOS 7+ apps.
    Could you share the implementation details for the same.
    Thanks.

  • Sudeb Sarkar

    The file “OAuthStarterKit” couldn’t be opened because you don’t have permission to view it. Help Me

  • jay patel

    Hi Manish! Thanks for your help on this. What is the key within the dictionary to access the user’s email, which they use for logging into linkedIn. If there is no key, can you explain where we should add permission within the code to access this email address. thank you!

    • Manish Kumar

      @Jay
      https://github.com/manishatinnofied/LinkedIn-Integration

      This is the link to a sample project where you can find all the details you need from the linkedIn response.

      • Matthew Bordas

        Hey Manish, me and Jay are working together and we already have downloaded the project and integrated it into our own. The main issue is the json object returned from the API request, inside the OAuthLoginView.m and the function testAPICallResult, when we try to retrieve the email using “email-address” as the key to self.profile (which is an NSDictionary) it crashes as the key does not exist. This was confusing because the url used to call the API contains “email-address” so the object returned should have the email address.

        We believe the problem lies in the permissions and that our app does not request the r_emailaddress permission required by linkedin to obtain the user’s email. We tried to find the code in the project that you used to request permissions, so that we could add on r_emailaddress, but we were unsuccessful in locating the code. Any help with this matter would be greatly appreciated, thank you.

        • Manish Kumar

          @matthewbordas:disqus Hey. I opened my project and after running the project everything is working perfectly for me. I suppose the key you are using to get email address should be “emailAddress” instead of “email-address”. You can refer to my project in Github: https://github.com/manishatinnofied/LinkedIn-Integration. In that also , I have parsed email using “emailAddress” key. In case your problem is not solved, please inform so that the issue can be resolved.

          • Matthew Bordas

            Ok that’s strange because these are the only keys we are getting back from the API call. This output is directly from your project. We are not sure what the problem is. Thanks!

          • Manish Kumar

            Can you please send me the snapshot of the whole response that you are getting from linkedIn?

          • Manish Kumar

            This is the snapshot of the response and keys I am getting from linkedIn.

          • jay patel

            Hey Manish,

            Thanks for your response. We were out of the office for the weekend and did not see your response til now. After looking at your updated projected on GitHub, I ran it with our linkedin keys and got the printout:

            2015-07-13 14:19:53.089 LinkedInPractice[20302:5546251] response body: {

            “formattedName”: “Matthew Bordas”,

            “id”: “wmh6oE7Z3b”,

            “industry”: “Computer Software”,

            “numConnections”: 395,

            “pictureUrl”: “https://media.licdn.com/mpr/mprx/0_GNQk2J-ThZ-9O0Kd8zvB2sr8CUkvYJ3durtR2UlggYKkTg9WmtneCRLPuzXwjOhLiBksip7sZPtu”,

            “positions”: {

            “_total”: 2,

            “values”: [

            {

            “company”: {“name”: “Developer”},

            “title”: “Software Engineer”

            },

            {

            “company”: {“name”: “Matthew Bordas”},

            “title”: “Personal Investor”

            }

            ]

            },

            “publicProfileUrl”: “https://www.linkedin.com/in/matthewbordas”,

            “summary”: “”.
            }

            As you can see, email is not there. Do you believe it is because of the level of access we were given within our keys from linkedin? Best,

            Jay

          • Jay Patel

            Hey Manish,
            Thanks for your replies. Sorry we have taken so long to get to you. We have been out for the weekend.

            In our project we are still unable to access the email within the JSON dictionary. Could the problem be that we do not have permisssion? I ran your project with our key values given from linkedin and this is the output:

            What do you believe we should do to receive the email?

            Thanks,

            Jay & Matt

          • Manish Kumar

            Hey Jay,
            No worries about late reply. I think the problem persists because of the permission of the keys. Check for the “r_emailaddress” permission for your project. Go to this link: https://www.linkedin.com/developer/apps/ and add the permission “r_emailaddress”.

          • Jay Patel

            Manish,

            Thank you so much. We really appreciate the support! it was a simple permissions issue.

            Best,

            Jay

          • Manish Kumar

            You are welcome Jay.

          • rohan

            Hello Manish, How to convert this Linkedin Integration in swift 2.0?

          • Manish Kumar

            Hello Rohan.

            Below is the link to linkedIn integration using swift 2.0 for iOS 9.0.

            https://github.com/manish-1612/LinkedIn-Integration-New

          • rohan

            Hello Manish,
            Thank you so much.
            Can we get news feed (wall posts) of user in the ios app?

          • Manish Kumar

            Welcome Rohan. I haven’t implemented that, but there must be some API to implement that. You can search the API docs of linkedin for such API.

            https://developer.linkedin.com/docs

            Please go through the above link, you will surely find something. If you face any difficulty, feel free to message here.

          • Jatin Vashisht

            Hello Manish, can you please help me in this task. i want the new feeds of my LinkedIn account but i dont know how to get .

          • Manish Kumar

            Hi Jatin,

            I haven’t done this thing, but this link http://stackoverflow.com/questions/29825152/implement-linkedin-feeds-in-ios might be useful.

          • Jatin Vashisht

            thanks for the reply

  • Stan

    Hi, very useful…. Just a question. I run your sample project. What would be the best way to manage the “cancel” button once you’re on the linkedin page? Currently it points to the defined url and I would like to go back to the initial view (where the Integrate linkedin appears) (or close the webview). Is it possible?

    • Manish Kumar

      Thanks Stan. In my project, when I click the “Cancel” button (appearing on the linkedIn login webview), the webview closes and page with button “Integrate LinkedIn” appears. You want this only, right?

      • Stan

        Exactly…

        • Manish Kumar

          It’s happening like that only here. Isn’t it happening there?

          • Stan

            using my linkedin parameters, when I click on the cancel button (from the linkedin form) I m redirected to the url that I set as “Default “Cancel” redirect URL.

          • Manish Kumar

            After linkedIn login is successful, do you want your app go to other page, or then also it will show “Integrate LinkedIn” page?

          • Stan

            In fact, the best would be to back to the Integrate Linkedin page with the result object..
            I have a login page and want to allow to the user to sign in with different social accounts (Facebook, Twitter and Linkedin)…
            The FB and Twitter seems to be ok and I m trying to understand how to adapt yours for the linkedin part…

          • Manish Kumar

            Ok. Then you can do this:
            Make the redirect url an empty string. Now in the app, when the login is successful,only then a notification is fired with name “loginViewDidFinish”. Under the selector (responding to this particular notification), write the segue code to your desired controller. Like this if login is successful, you will be redirected to another page as you demand, else you will remain on the login page.

            I know its not the proper way to respond to the problem, but for immediate solution it can be tried out.

          • Stan

            I’ll make a try… I thank you very much..

          • Manish Kumar

            Don’t mention it.. 🙂

  • Oye Lan

    HI, after i drag the three file, the Xcode show several warning about the ARC, what should i do about this ?

    • Manish Kumar

      Hey Oye.
      Go to project settings, then Build Phases , and then Compile Sources.
      Under that you should add “fno-objc-arc” to the .m of those files which are showing ARC related issues.

      • Oye Lan

        yes, i have done this but its warning that fno-objc-arc not found

      • Oye Lan

        thks Kumar , it works, thks for your help

        • Manish Kumar

          You are welcome Oye.

  • Vinayak Koti

    Maish m new to ios,m working on swift so can u plz help to knw wat all fields i can access throug oath linked in api, and plz provide the source code for sample so that i can refer to that….

    • Manish Kumar

      Hi Vinayak, I have not really implemented the oAuth LinkedIn API with swift but I can help you out with some links that illustrate how to use linkedIn oAuth API.

      1. The link to authenticate as a linkedIn user through oAuth : https://developer.linkedin.com/docs/oauth2

      2. The link on how to use permissions and profile fields. : https://developer.linkedin.com/docs/fields

      If you still face any difficulty, please let me know.

  • Matthew Bordas

    Hey Manish thank’s again for this AMAZING project. With iOS 9 I now sometimes get this exception thrown once I press “Sign in” on the webview for LinkedIn. I’m not sure why this is happening now with ios 9, I haven’t not modified any of the core lines of code. Thank you!

    • Manish Kumar

      Hey Matthew. I am looking into the issue. Is this happening always or sometimes?

    • Manish Kumar

      Hey Matthews, I also got the same issue. I suppose, the linkedIn library that we are using has got some compatibility issues with iOS 9.0 because of which its getting Bad Access error . I suppose we will have to follow the new LinkedIn documentation for iOS 9.0.

      • Matthew Bordas

        In response to your first message, it only happens somtimes, but I feel it is frequent enough to warrant a fix.

        To your second message, alright then I’m you were able to trigger it as well. Do you have any idea which files could be causing it? The OAuth Starter Kit I presume? I’ll look into the files/library more myself as well tomorrow! Thank you so much! Hopefully we can figure this out and it will be a simple fix.

        • Manish Kumar

          Thank You Matthew. I am working on the new SDK that LinkedIn provides to give iOS 9.0 support. If you are able to fix the issue, please share the solution here as well so that others are not stuck with the same.

          • Matthew Bordas

            Any luck? I have been unsuccessful

          • Manish Kumar

            Hey Matthew. I was out for some days, so wasn’t able to work on that. I will try that today onwards.

    • Testers TestAccount

      me too facing same problem …. 🙂

      • Manish Kumar

        @matthewbordas:disqus @testerstestaccount:disqus I have completed the iOS 9.0 support for LinkedIn through its new iOS SDK. Here is the URL : https://github.com/manish-1612/LinkedIn-Integration-New

        But with this there is one drawback, you will have to test it on a device as it requires LinkedIn App to get through the whole process. And simulator doesn’t have one, neither it can be downloaded in simulator.

        Also to remind you please change the keys as per your application settings. For more details on application settings please go through the following link : https://developer.linkedin.com/docs/ios-sdk

        Feel free to comment, if you face any problem.

        • Matthew Bordas

          Thank you so much, I am going to test it out today. Your help is truly appreciated!!

        • Matthew Bordas

          Is there a way to use the web view from the old project to circumvent requiring the user to have the linkedin app?
          Also I see that the CLIENT_ID and CLIENT_SECRET are defined in the prefix header, but I’m not sure how the linkedin api knows to use those? Does the linkedin api just use those macros?

          • Manish Kumar

            Hi Matthew. I tried to use the old integration method for iOS 9.0 but since it is crashing very often, I don’t think it will be good enough to use for iOS 9.0 apps.
            Coming to prefix header, I declared CLIENT_ID and CLIENT_SECRET in prefix header as from there it will be accessible to all. if you don’t want to use prefix header, you can locally use the static data in whichever file it is required.

          • Matthew Bordas

            Ok hmmm all I really want is a way around forcing the user to download the linkedin app in order to log in with linkedin. Do you think it can be done?

          • Manish Kumar

            Let me check the feasibilty and come back to you.

          • Matthew Bordas

            Thank you so much!

          • Manish Kumar

            You’re welcome Matthew.

          • Matthew Bordas

            Any updates? Thanks!

          • Manish Kumar

            Hey Matthew. I searched for alternatives but I couldn’t find any. It’s like we would have to rectify the old version.

          • Matthew Bordas

            Yeah that’s what I figured. Can we make api calls with the old version as long as we update it?

          • Manish Kumar

            Hope so. Can’t confirm that. I am working on some other project so can’t try that now itself. But will try it when it’s over.

          • Matthew Bordas

            Thanks!

          • Jay Patel

            Hi Manish, I work with Matthew.

            Do you have an update? Thanks for your help,

            Jay

  • Tester Singh

    Hi manish,

    How we can share url or image with this ? Any help.

  • Tester Singh

    How we can share (url,image,string) on linked-in ?

    • Manish Kumar

      Haven’t tried yet. Please go through the LinkedIn API docs for that.

  • Karthik_k

    how to get the education details? i tried with following url but education details are not showing

    NSURL *url = [NSURL URLWithString:@”https://api.linkedin.com/v1/people/~:(id,first-name,last-name,maiden-name,formatted-name,email-address,location:(name),industry,public-profile-url,picture-url,primary-twitter-account,network,skills,summary,phone-numbers,date-of-birth,main-address,positions:(title,company:(name)),educations:(school-name,field-of-study,start-date,end-date,degree,activities))”];

  • Manish Kumar

    While doing the same for iOS 9.0 , i was also facing the same issue. Didn’t find any solution till now.

    • Karthik_k

      Thanks for reply,but i am facing this problem in 8.4 also

      • Manish Kumar

        For iOS please try the 8.4 one, that is done with swift. Hope that solves your problem. Here’s the link : https://github.com/manish-1612/LinkedIn-Integration-New

        • Karthik_k

          Already tried this code but i didn’t get any results for education and updated experience details

  • Ashiwani Singh

    When I preess cancel button then view did not dismiss and getting below message,please help out.

    WebKit discarded an uncaught exception in the webView:decidePolicyForNavigationAction:request:frame:decisionListener: delegate: *** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[1]

  • Karthik_k

    how to get the large image from picture url from linked in?

  • Roohul Amin Khan

    Hi Manish…
    Can u please add me as a connection in LinkedIn
    My email id is roohulamin.khan@gmail.com

    I tried to get connected to u through Facebook and other sources but couldn’t find one.

    Sorry for requesting things like this here….. 🙁