我想在我的应用中包含“使用 LinkedIn 注册”功能。
我希望能够获得一些信息,例如姓名和电子邮件。
默认情况下,我可以获得一个名字,但我无法收到电子邮件。
我的结果是 JSON 格式的。
这是我的代码:
- (IBAction)logInWithLinkedIn:(id)sender
{
if ([_client validToken])
{
[self requestMeWithToken:[_client accessToken]];
}
else
{
[_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/~?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:@"redirectURL"
clientId:@"key"
clientSecret:@"secret"
state:@"state"
grantedAccess:@[@"r_emailaddress"]];
return [LIALinkedInHttpClient clientForApplication:application presentingViewController:nil];
}
我的结果是:
名字
标题
姓氏
siteStandardProfileRequest
有人知道我怎样才能收到电子邮件吗?
最佳答案
你应该使用:
[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)
这可能会有所帮助:)
关于ios - 从 LinkedIn API 获取电子邮件地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23123347/