【问题标题】:Not getting full profile while trying to import data from linkedIn using oAuth 2尝试使用 oAuth 2 从linkedIn 导入数据时未获取完整配置文件
【发布时间】:2014-07-14 12:55:26
【问题描述】:

我正在构建一个应用程序并使用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);
    }];

}

输出:

我什至得到了这个屏幕。

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";
    };
}

【问题讨论】:

  • 同样的问题。有什么建议吗?
  • 还没有。找到解决方案后,我会在这里发布。
  • 找到解决方案 - (void)requestMeWithToken:(NSString *)accessToken { [self.client GET:[NSString stringWithFormat:@"api.linkedin.com/v1/people/…", accessToken] 参数:nil 成功:^(AFHTTPRequestOperation *operation, NSDictionary *result) { NSLog(@"当前用户 %@", result); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"获取当前用户失败 %@", error); }]; }
  • 你能解释一下我哪里出错了,或者我必须使用你提供的上述代码吗..
  • 在您的 -(IBAction)linkedInButtonClicked:(id)sender 方法中,您可以像这样编辑 [NSString stringWithFormat:@"api.linkedin.com/v1/people/…", accessToken]

标签: ios iphone oauth-2.0 linkedin


【解决方案1】:
- (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];
}

【讨论】:

  • 你知道如何使用这个库在链接中分享 url
  • 你的意思是用这个发布一些东西到linkedIn?
  • 我还没有调查,但我一定会花一些时间来帮助你。
  • github.com/pmilanez/MIS-Linkedin-Share 试试这个,它可能对你有帮助。
猜你喜欢
  • 2013-09-08
  • 2013-01-19
  • 1970-01-01
  • 2015-07-12
  • 2013-01-12
  • 2015-04-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多