如何从ios中的linkedIn API获取电子邮件地址?

时间:2015-01-16 12:09:48

标签: ios objective-c linkedin

我使用过IOSLinkedInAPI。我想获取用户信息。我收到了一些用户信息但没有收到电子邮件地址。我使用下面的代码..

- (void)viewDidLoad {
    [super viewDidLoad];

 _client = [self client];
}

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

}
- (LIALinkedInHttpClient *)client {
    LIALinkedInApplication *application = [LIALinkedInApplication applicationWithRedirectURL:@"http://www.ancientprogramming.com/liaexample"
                                                                                    clientId:LINKEDIN_CLIENT_ID
                                                                                clientSecret:LINKEDIN_CLIENT_SECRET
                                                                                       state:@"DCEEFWF45453sdffef424"
                                                                               grantedAccess:@[@"r_basicprofile",@"r_emailaddress"]];
    return [LIALinkedInHttpClient clientForApplication:application presentingViewController:nil];
}
- (void)requestMeWithToken:(NSString *)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);
        profileUrl = [[result valueForKey:@"siteStandardProfileRequest"] valueForKey:@"url"];

        [self profileInfoGetMethod:[[result valueForKey:@"siteStandardProfileRequest"] valueForKey:@"url"]];

    }        failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"failed to fetch current user %@", error);
    }];
}


so, I got result like



firstName = 
headline = 
lastName = 
siteStandardProfileRequest = {
url = "";
};

但未获取电子邮件地址,请提供适用于我的代码的任何建议或源代码。

谢谢

0 个答案:

没有答案