如何在iOS SDK中获取LinkedIn连接/朋友/联系人?

时间:2013-07-11 08:20:15

标签: iphone ios linkedin

我想从我的LinkedIn个人资料中获取所有朋友。请建议我任何教程。

我的代码是:

NSURL *url = [NSURL URLWithString:@"http://api.linkedin.com/v1/people/~/connections:(id,first-name,last-name,email-address,picture-url,Positions)"];
OAMutableURLRequest *request = [[OAMutableURLRequest alloc] initWithURL:url
                                                               consumer:self.oAuthLoginView.consumer
                                                                  token:self.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:)];

2 个答案:

答案 0 :(得分:0)

您可以将此用于连接:For request part see this.

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

        NSLog(@"connectionsApiCallResult====%@",responseBody);

        [responseBody release];
    }

    - (void)connectionsApiCallResult:(LOAServiceTicket *)ticket didFail:(NSError *)error
    {
        NSLog(@"%@",[error description]);

    }

    -(void)GetConnectionsCall
    {
        NSURL *url = [NSURL URLWithString:@"http://api.linkedin.com/v1/people/~/connections:(headline,first-name,last-name,picture-url,id)"];

        LOAMutableURLRequest *request =
        [[LOAMutableURLRequest alloc] initWithURL:url
                                        consumer:self.consumer
                                           token:TestAccessToken
                                        callback:nil
                               signatureProvider:nil];

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

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

    }

答案 1 :(得分:0)

请尝试以下步骤

  1. 首先转到https://www.linkedin.com/secure/developer编辑您的应用范围,确保您已检查过r_network范围。
  2. 然后转到项目的 OAuthLoginView ,然后转到 - (void)requestTokenFromProvider 方法。
  3. 在下面的行中编辑范围。

    OARequestParameter *nameParam = [[OARequestParameter alloc] initWithName:@"scope"
    value:@"r_fullprofile+rw_nus+r_network"];
    
    OARequestParameter * scopeParameter=[OARequestParameter requestParameter:@"scope" 
    value:@"r_fullprofile rw_nus r_network"];