Search code examples
iosobjective-clinkedin-api

issue regarding Integrate Linkedin in ios


I am newbie and there needs to integrate linkedin in my application. I have generated client id and client secret. I have read the documentation of linkedin but every time I GET some error so please guide me through the same. For get request I have tried this but don't know what to write inside

   [[LISDKAPIHelper sharedInstance]getRequest:(NSString *)url success:^(LISDKAPIResponse *) {

    } error:^(LISDKAPIError *)
     {

    }];

I even written in AppDelegate class

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    if ([LISDKCallbackHandler shouldHandleUrl:url]) {
        return [LISDKCallbackHandler application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
    }
    return YES;
}

Solution

  • Create an outlet for UIButton in your ViewController

    In your info.plist add following under LSApplicationQueriesSchemes

    1. linkedin-sdk
    2. linkedin-sdk2

    Also add your linkedin app id in your plist file. In your ViewController do this:

    -(void) linkedinTap{
    
        NSArray *permissions = [NSArray arrayWithObjects:LISDK_BASIC_PROFILE_PERMISSION, nil];
        [LISDKSessionManager createSessionWithAuth:permissions state:nil showGoToAppStoreDialog:YES successBlock:^(NSString *returnState)
        {
            NSLog(@"%s","success called!");
            LISDKSession *session = [[LISDKSessionManager sharedInstance] session];
            NSLog(@"Session : %@", session.description);
        } errorBlock:^(NSError *error)
        {
            NSLog(@"%s","error called!");
        }];
    }
    
    -(void) getRequest:(NSString*)token{
    
        [[LISDKAPIHelper sharedInstance] getRequest:@"https://api.linkedin.com/v1/people/~"
                                            success:^(LISDKAPIResponse *response)
        {
            NSData* data = [response.data dataUsingEncoding:NSUTF8StringEncoding];
            NSDictionary *dictResponse = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
            NSLog(@"Authenticated user name : %@ %@", [dictResponse valueForKey: @"firstName"], [dictResponse valueForKey: @"lastName"]);
        } error:^(LISDKAPIError *apiError)
        {
            NSLog(@"Error : %@", apiError);
        }];
    }
    

    In your AppDelegate

    - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
        return [LISDKCallbackHandler application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
        return YES;
    }