gpt4 book ai didi

ios - 从LinkedIn API获取电子邮件地址

转载 作者:行者123 更新时间:2023-12-01 16:36:15 25 4
gpt4 key购买 nike

我想在我的应用程序中包括“使用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/27983666/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com