I want to display the user profile photo and his profile field such as company-name, job title, industry, and location. I call ProfilePicCall to retrieve the profile picture.
- (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:)];
}
Then to display the photo in image view I use the below code
- (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"];
}
But the image not display in the image view. Please help me to display the image, and how to use LinkedIn API
Thanks.
I found the solution for my question, it should change the LinkedIn API call to be:
- (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:)];
}
Thanks.