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.
Go to this OAuth Starter Kit link and download the OAuth Kit for LinkedIn.
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.
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)initLinkedInApi, assign 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 :
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.