关于在 ios 中集成 Linkedin 的问题

issue regarding Integrate Linkedin in ios

我是新手,需要在我的应用程序中集成linkedin。我已经生成了客户端 ID 和客户端密码。我已经阅读了 linkedin 的文档,但每次我遇到一些错误时,请指导我完成相同的操作。 对于 get 请求我试过这个但是不知道里面写什么

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

    } error:^(LISDKAPIError *)
     {

    }];

我什至写在AppDelegateclass

- (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;
}
         [LISDKSessionManager createSessionWithAuth:[NSArray arrayWithObjects:LISDK_W_SHARE_PERMISSION, nil]
                                                             state:@"some state"
                                            showGoToAppStoreDialog:YES
                                                      successBlock:^(NSString *returnState) {

                                                          NSLog(@"%s","success called!");
                                                          NSLog(@"Access Token: %@", [[[LISDKSessionManager sharedInstance] session].accessToken description]);

      NSString *url = @"https://api.linkedin.com/v1/people/~/shares";
      NSString *str = @"Your String";
      NSString *payload = @"Your Payload";
     if ([LISDKSessionManager hasValidSession]) {
                                                              [[LISDKAPIHelper sharedInstance] postRequest:url stringBody:payload
                                                                                                   success:^(LISDKAPIResponse *response) {
                                                                                                       // do something with response
                                                                                                       NSLog(@"%s","success called!");
                                                                                                       UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Linkedin" message:@"Shared successfully." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
    [alert show];
                                                                                                   }
                                                                                                     error:^(LISDKAPIError *apiError) {
                                                                                                         // do something with error
                                                                                                         NSLog(@"%s","error called!");                                                                                                UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Oops!" message:@"There was a problem sharing. Please try again later." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
                                                                                                         [alert show];
                                                                                                     }];
                                                          }
                                                      }
                                                        errorBlock:^(NSError *error) {
NSLog(@"%s %@","error called! ", [error description]);
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Oops!" message:@"There was a problem sharing. Please try again later." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
[alert show];
}
];

希望对您有所帮助

在 ViewController

中为 UIButton 创建一个出口

在您的 info.plist 中,在 LSApplicationQueriesSchemes

下添加以下内容
  1. linkedin-sdk
  2. linkedin-sdk2

同时在您的 plist 文件中添加您的 linkedin 应用程序 ID。在您的 ViewController 中执行此操作:

-(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);
    }];
}

在您的 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;
}