ios - 尝试使用 oAuth 2 从 linkedIn 导入数据时未获得完整配置文件

标签 ios iphone oauth-2.0 linkedin

我正在构建一个应用程序并使用 linkedIn oAuth2.0 进行身份验证并获取用户的个人资料数据,但不知何故我无法获得用户的完整个人资料信息。我正在使用 iOSLinkedInAPI 库进行身份验证。

这是我的代码。

    - (void)viewDidLoad
    {
        NSArray *grantedAccess = @[@"r_fullprofile", @"r_network", @"r_emailaddress"];

        NSString *clientId = @"client_id"; 
        NSString *clientSecret = @"clientSecret"; 
        NSString *state = @"state"; 
        LIALinkedInApplication *application = [LIALinkedInApplication applicationWithRedirectURL:@"linkedin_login_redirect_url" clientId:clientId clientSecret:clientSecret state:state grantedAccess:grantedAccess];
        self.client = [LIALinkedInHttpClient clientForApplication:application];
}


-(IBAction)linkedInButtonClicked:(id)sender
{
    NSLog(@"did press login");
    [self.client getAuthorizationCode:^(NSString *code) {
        [self.client getAccessToken:code success:^(NSDictionary *accessTokenData) {
            NSString *accessToken = [accessTokenData objectForKey:@"access_token"];
            NSLog(@"%@",accessToken);
            [self.client GET:[NSString stringWithFormat:@"https://api.linkedin.com/v1/people/~?oauth2_access_token=%@&format=json", accessToken] parameters:nil success:^(AFHTTPRequestOperation *operation, NSDictionary *result) {
                NSLog(@"current user %@", result);
            }            failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                NSLog(@"failed to fetch current user %@", error);
            }];
        }                   failure:^(NSError *error) {
            NSLog(@"Quering accessToken failed %@", error);
        }];
    }                          cancel:^{
        NSLog(@"Authorization was cancelled by user");
    }                         failure:^(NSError *error) {
        NSLog(@"Authorization failed %@", error);
    }];

}

输出:

我什至看到了这个屏幕。

enter image description here

MyApp[723:60b] current user {
    firstName = XYZ;
    headline = "something at something";
    lastName = XYZ;
    siteStandardProfileRequest =     {
        url = "http://www.linkedin.com/profile/view?id=12345&authType=name&authToken=something";
    };
}

最佳答案

- (IBAction)didTapBtn:(id)sender {
    [self.client getAuthorizationCode:^(NSString *code) {
        [self.client getAccessToken:code success:^(NSDictionary *accessTokenData) {
            NSString *accessToken = [accessTokenData objectForKey:@"access_token"];
            [self requestMeWithToken:accessToken];
        }                   failure:^(NSError *error) {
            NSLog(@"Quering accessToken failed %@", error);
        }];
    }                      cancel:^{
        NSLog(@"Authorization was cancelled by user");
    }                     failure:^(NSError *error) {
        NSLog(@"Authorization failed %@", error);
    }];
}


- (void)requestMeWithToken:(NSString *)accessToken {
    [self.client GET:[NSString stringWithFormat:@"https://api.linkedin.com/v1/people/~:(id,first-name,last-name,maiden-name,email-address)?oauth2_access_token=%@&format=json", accessToken] parameters:nil success:^(AFHTTPRequestOperation *operation, NSDictionary *result) {
        NSLog(@"current user %@", result);
    }        failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"failed to fetch current user %@", error);
    }];
}


- (LIALinkedInHttpClient *)client {
    LIALinkedInApplication *application = [LIALinkedInApplication applicationWithRedirectURL:@"https://www.example.com"
                                                                                    clientId:@"xxxxxxxxx"
                                                                                clientSecret:@"xxxxxxxxx"
                                                                                       state:@"xxxxxx"
                                                                               grantedAccess:@[@"r_fullprofile",@"r_emailaddress",@"r_network",@"r_contactinfo"]];
    return [LIALinkedInHttpClient clientForApplication:application presentingViewController:nil];
}

关于ios - 尝试使用 oAuth 2 从 linkedIn 导入数据时未获得完整配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24661673/

相关文章:

ios - UITableView 中重复使用的单元格会导致发生不需要的操作

ios - 我可以以某种方式删除动画以防出现推送转场吗

iphone - 检测 iPad 键盘隐藏与外部键盘连接?

iphone - 帮助理解 OpenGL 的 Xcode 4 项目模板

java - 在新的 Google Apps Marketplace OAuth 2 流程下,您是否注册回调 URL?

ios - 在缩放图像上画线

ios - 两个基于内容的自定义 tableviewcell 高度

iphone - afnetworking 多文件上传

使用 cy.request() 使用 Cypress 登录 Azure B2C

java - 无法使用 access_token : spring boot Oauth2 访问资源