Narendra Pandey Narendra Pandey - 1 year ago 96
Objective-C Question

issue regarding getting user data in linkedin

actually i am using OAuth 2.0. and used class of afnetworking, displayed Linkedin login page by using webview giving url as a client key and their authorization end Point,response type and state. everything is working

-(void)requestforAccessToken:(NSString *)authorisationCode
NSString *grantType = @"authorization_code";

NSString *postParameter = [NSString stringWithFormat:@"grant_type=%@&code=%@&redirect_uri=%@&client_id=%@&client_secret=%@",grantType,authorisationCode,encodedRdirectURL,linkedInKey,linkedInSecret];

NSData *postdata = [postParameter dataUsingEncoding:NSUTF8StringEncoding];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:accessTokenEndPoint]];

request.HTTPMethod = @"POST";
request.HTTPBody = postdata;
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];

AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];

manager.responseSerializer = [AFJSONResponseSerializer

[[manager dataTaskWithRequest:request completionHandler:^(NSURLResponse * response, id responseObject, NSError * error )
if (!error)
NSLog(@"Reply JSON: %@", responseObject);

NSString *accessToken = [responseObject objectForKey:@"access_token"];

NSLog(@"Access Token %@",accessToken);

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

[defaults setObject:accessToken forKey:@"linkedInAccessToken"];

[defaults synchronize];

}] resume];


By using this method i get Access token now my question is How to get user data like profile pic and all basic data. is thhere is any solution like facebook, just append accesstoken and u will get JSON data. Even i don't want to use SDK of linkedin , want direct communication so Please help. Thank You

Answer Source

Here is the URL I use to get all possible informations from a LinkedIn user (without partnership with LinkedIn) :

[NSString stringWithFormat:@",last-name,id,industry,location,headline,specialties,current-share,summary,picture-url,email-address,positions)?oauth2_access_token=%@&format=json", accessToken]

The accessToken is the one you just get right after authentification.

Just make a GET request with AFNetworking on this URL and you'll receive, as you said, a JSON reply which looks like this :

    emailAddress = "****";
    firstName = Pi***e;
    headline = "Developpeur iOS chez Pi****e";
    id = 6Z***bFH3;
    industry = "Computer Software";
    lastName = "Test Account";
    location =     {
        country =         {
            code = fr;
        name = "Paris Area, France";
    pictureUrl = "*****U-9SswsbZKo3J*********eyCoHgYQadNFGRWQDyCwHjBVSdN4dVyw6gBFGIuQ3ZGnWmtsSdZUTjhIXErcmklEA7X";
    positions =     {
        "_total" = 1;
        values =         (
                company =                 {
                    name = Pi****e;
                id = 823***52;
                isCurrent = 1;
                location = {
                title = "Developpeur iOS";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download