使用发布请求在iOS中接收LinkedIn用户个人资料信息

时间:2015-02-26 12:42:11

标签: ios post linkedin

我正在寻找一种通过发帖请求来检索LinkedIn用户的个人资料信息的方法,我已经阅读了这两个LinkedIn页面,但它似乎没有解释太多,或者我无法理解它:

REST API LinkedIn basic profile informations

我在stackoverflow上看过这些例子,但我对此并不了解:

http://api.linkedin.com/v1/people/~:(id,first-name,last-name,maiden-name,email-address,formatted-name,phonetic-last-name,location:(country:(code)),industry,distance,current-status,current-share,network,skills,phone-numbers,date-of-birth,main-address,positions:(title),educations:(school-name,field-of-study,start-date,end-date,degree,activities)) 

我只对检索网站上显示的技能部分感兴趣:

enter image description here

4 个答案:

答案 0 :(得分:1)

通过Kirsten Jones有一个很棒的LinkedIn-iOS集成库,您可以使用它来调用LinkedIn API。您需要一个访问令牌才能拨打电话。

https://github.com/PrincessPolymath/LinkedIn-OAuth-Sample-Client

拨打这样的电话:

NSURL *url = [NSURL URLWithString:@"http://api.linkedin.com/v1/people/~:(id,first-name,last-name,maiden-name,formatted-name,phonetic-last-name,location:(country:(code)),industry,distance,current-status,current-share,network,skills,phone-numbers,date-of-birth,main-address,positions:(title),educations:(school-name,field-of-study,start-date,end-date,degree,activities))"]];
    OAMutableURLRequest *request = 
    [[OAMutableURLRequest alloc] initWithURL:url
                                    consumer:oAuthLoginView.consumer
                                       token:oAuthLoginView.accessToken
                                    callback:nil
                           signatureProvider:nil];

    [request setValue:@"json" forHTTPHeaderField:@"x-li-format"];

    OADataFetcher *fetcher = [[OADataFetcher alloc] init];
    [fetcher fetchDataWithRequest:request
                         delegate:self
                didFinishSelector:@selector(profileApiCallResult:didFinish:)
                  didFailSelector:@selector(profileApiCallResult:didFail:)];    

- (void)profileApiCallResult:(OAServiceTicket *)ticket didFinish:(NSData *)data 
{
    NSString *responseBody = [[NSString alloc] initWithData:data
                                                   encoding:NSUTF8StringEncoding];

    NSDictionary *profile = [responseBody objectFromJSONString];

    if ( profile )
    {
        name.text = [[NSString alloc] initWithFormat:@"%@ %@",
                     [profile objectForKey:@"firstName"], [profile objectForKey:@"lastName"]];
        headline.text = [profile objectForKey:@"headline"];

        .....and get skills and other user details

     }    
}

答案 1 :(得分:1)

使用工具:https://apigee.com/console/linkedin

获取技能列表的API: https://api.linkedin.com/v1/people/~:(id,num-connections,skills)?format=json

我在控制台工具中尝试了它,并且能够获取我的个人资料的技能。我认为具有上述要求的个人技能ID应该可以帮助您获得更多信息。试试看。

答案 2 :(得分:1)

我在使用linkedIn API方面有相当多的经验。这已经有一段时间了,但希望这会让你走上正轨。

要从链接的用户获取个人资料信息,您需要以下格式:

NSString *theRequest = [NSString stringWithFormat:@"https://api.linkedin.com/v1/people/id=abc123:(first-name,last-name,picture-url,location:(name))?oauth2_access_token=%@&format=json", accessToken];

此请求将返回第一个名称,姓氏,个人资料图片网址以及指定了ID的用户的位置。

您可以在此处查看有关其个人资料字段说明的linkedIn文档,以查看您可以请求的字段类型列表: https://developer.linkedin.com/docs/fields

如果您想知道如何首先获取您想要请求其个人资料信息的用户的ID,您可以请求所有连接的一些基本信息(包括ID),如下所示:

NSString *basicConnectionInfo = [NSString stringWithFormat:@"https://api.linkedin.com/v1/people/~/connections:(id,first-name,last-name)?oauth2_access_token=%@&format=json", accessToken];

此请求将为您提供所有连接的ID,名字和姓氏。在获得所需人员的ID后,您可以使用用户的ID发出请求(如第一个示例所示)。

现在有点遗憾的消息......如果您按照上面提供的链接,您会注意到技能字段是“可以向LinkedIn开发人员申请的会员资料字段”的一部分。我假设您必须按照他们提供的链接https://developer.linkedin.com/docs/apply-with-linkedin才能访问技能成员资料字段。

我还没有申请过LinkedIn。所以,我还没有测试过对技能字段的调用。但是,我猜它会与我向你展示的例子类似。希望这可以帮助!

答案 3 :(得分:1)

如果有人正在阅读此答案,则截至2015年5月,LinkedIn API的访问权限有限。您需要申请他们的LinkedIn应用程序以访问完整的个人资料字段,包括技能。

https://developer.linkedin.com/docs/fields