Luk*_*vin 5 oauth objective-c linkedin ios
我想在我的应用中添加"使用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];
}
Run Code Online (Sandbox Code Playgroud)
我的结果是:
名字
标题
姓
siteStandardProfileRequest
有人知道我怎么能收到这封电子邮件吗?
alp*_*urt 10
你应该使用:
[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)
Run Code Online (Sandbox Code Playgroud)
这可能有帮助:)
| 归档时间: |
|
| 查看次数: |
5858 次 |
| 最近记录: |