簡體   English   中英

嘗試使用oAuth 2從linkedIn導入數據時未獲取完整的配置文件

[英]Not getting full profile while trying to import data from linkedIn using oAuth 2

我正在構建一個應用程序,並使用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);
    }];

}

OUTPUT:

我什至得到這個屏幕。

在此處輸入圖片說明

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM