从 LinkedIn API 获取电子邮件地址 [英] Getting Email Address from LinkedIn API

查看:55
本文介绍了从 LinkedIn API 获取电子邮件地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用中加入使用领英注册"功能.

I want to include a "Sign Up using LinkedIn" feature in my app.

我希望能够获得一些信息,例如姓名和电子邮件.

I'd like to be able to get some information, such as name and email.

默认情况下,我可以获得姓名,但我一直无法收到电子邮件.

By default I am able to get a name, but I'm stuck on getting the email.

我的结果是 JSON.

My results are in 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

siteStandardProfileRequest

有人知道我怎样才能收到电子邮件吗?

Anyone see how I can get the email?

推荐答案

你应该使用:

[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)

这可能有帮助:)

这篇关于从 LinkedIn API 获取电子邮件地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆