2013-07-27 195 views
0

我想显示用户个人资料照片和他的个人资料字段,如公司名称,职位,行业和位置。 我打电话给ProfilePicCall来检索个人资料图片。显示LinkedIn个人资料照片和用户个人资料使用LinkedIn API

- (void)ProfilePicCall 
{ 
    NSURL *url = [NSURL URLWithString:@"http://api.linkedin.com/v1/people/~/picture-url"]; 
    OAMutableURLRequest *request = 
    [[OAMutableURLRequest alloc] initWithURL:url 
            consumer:oAuthLoginView.consumer 
             token:oAuthLoginView.accessToken 
            callback:nil 
          signatureProvider:nil]; 

    NSLog(@"the request is %@",request); 


    [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]; 
    // [responseBody release]; 

    if (profile) 
    { 
     NSLog(@"Profile is %@",profile); 

    NSString *picture_url = [[NSUserDefaults standardUserDefaults]valueForKey:@"linkedid_Profile_url"]; 

     NSURL *imageurl = [NSURL URLWithString:picture_url]; 

     NSData *imagedata = [[NSData alloc]initWithContentsOfURL:imageurl]; 

     UIImage *image = [UIImage imageWithData: imagedata]; 
     [LinkedInPicture setImage:image]; 

    } 
    else 
    { 
     NSDictionary *profile = [responseBody objectFromJSONString]; 
     NSLog(@"last path componemt is %@",profile); 

    } 
    // The next thing we want to do is call the network updates 
    [self networkApiCall]; 
    [[NSUserDefaults standardUserDefaults] setValue:@"Used" forKey:@"linkedin"]; 

} 

但图像不是在图像视图中显示。请帮我展示图片,以及如何使用LinkedIn API

谢谢。

回答

5

我找到了解决我的问题,它应该改变LinkedIn的API调用是:

- (void)profileApiCall 
{ 

// NSURL *url = [NSURL URLWithString:@"http://api.linkedin.com/v1/people/~"]; 
    NSURL *url = [NSURL URLWithString:@"http://api.linkedin.com/v1/people/~:(id,first-name,last-name,industry,picture-url,location:(name),positions:(company:(name),title),specialties,date-of-birth,interests,languages)"]; 

OAMutableURLRequest *request = 
[[OAMutableURLRequest alloc] initWithURL:url 
           consumer:oAuthLoginView.consumer 
            token:oAuthLoginView.accessToken 
           callback:nil 
         signatureProvider:nil]; 

NSLog(@"the request is %@",request); 


[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:)]; 


} 

感谢。

+0

我没有得到用户个人资料网址我使用相同的code.any原因是什么? –

+0

@ Darshan: - 我使用相同的代码,它的工作完美,再试一次 – ravinder521986

1

我不喜欢上面的方法,

首先,我使用这个库与Auth2.0帮助记录过程在LinkedIn https://github.com/jeyben/IOSLinkedInAPI

如下使用它或阅读文档和更改代码由你自己。

解决的办法是申请https://api.linkedin.com/v1/people/~:(picture-url)?oauth2_access_token= &格式= JSON

LIALinkedInApplication *application = [LIALinkedInApplication applicationWithRedirectURL:@"http://www.ancientprogramming.com/liaexample" 
                        clientId:@"clientId" 
                       clientSecret:@"clientSecret" 
                        state:@"DCEEFWF45453sdffef424" 
                      grantedAccess:@[@"r_fullprofile", @"r_network"]]; 



LIALinkedInHttpClient *client = [LIALinkedInHttpClient clientForApplication:application presentingViewController:nil]; 

[client getAuthorizationCode:^(NSString *code) { 
    [client getAccessToken:code success:^(NSDictionary *accessTokenData) { 
     NSString *accessToken = [accessTokenData objectForKey:@"access_token"]; 
     //here you already have you access token 
     //SOLUTION == https://api.linkedin.com/v1/people/~:(picture-url)?oauth2_access_token=<ACCESS_TOKEN>&format=json 
     //make a http request and get the result with an image url 

    } cancel:^{ 
    NSLog(@"Authorization was cancelled by user"); 
    } failure:^(NSError *error) { 
    NSLog(@"Authorization failed %@", error); 
    }]; 
} 

工作正常,我

+1

谢谢,你只是在评论中提出解决方案,这就是为什么人们无法找到它。 https://api.linkedin.com/v1/people/~:(picture-url)?oauth2_access_token=&format=json –

相关问题