Oauth Invitation API issues

2 posts / 0 new
Last post
Karthik Navaneethan Manimaran's picture
Joined: 07/25/2011
Thu, 02/09/2012 - 11:57
Oauth Invitation API issues

I've been having issues the past couple of days using LinkedIn Invitation API. I am using the OAuth sample client here - https://github.com/synedra/LinkedIn-OAuth-Sample-Client

Am able to successfully post a share using your example in OAuthLoginView. However am unable to use the invitations API to post a message. I've pasted the code am using below.

NSURL *url = [NSURL URLWithString:@"http://api.linkedin.com/v1/people/~/mailbox"];

OAMutableURLRequest *request =

[[OAMutableURLRequest alloc] initWithURL:url

consumer:oAuthLoginView.consumer

token:oAuthLoginView.accessToken

callback:nil

signatureProvider:nil];

[request setHTTPMethod:@"POST"];

NSString *messageToPerson = @"/people/email=cyrille.denervaux@gmail.com";

//[NSString stringWithFormat:@"/people/%@",@"2025681"];

NSDictionary *person = [[NSDictionary alloc] initWithObjectsAndKeys:[[[NSDictionary alloc] initWithObjectsAndKeys:messageToPerson,@"_path",@"Cyrille",@"first-name",@"de Nervaux",@"last-name",nil] autorelease], @"person",nil]; //me: TuIMe113ZF

NSArray *valueArray = [[NSArray alloc] initWithObjects:person,nil];

NSDictionary *values = [[NSDictionary alloc] initWithObjectsAndKeys:valueArray,@"values", nil];

NSDictionary *ir = [[NSDictionary alloc] initWithObjectsAndKeys:[[[NSDictionary alloc] initWithObjectsAndKeys:@"friend",@"connect-type",nil] autorelease], @"invitation-request",nil];

NSDictionary *ic = [[NSDictionary alloc] initWithObjectsAndKeys:ir,@"item-content", nil];

NSDictionary *update = [[NSDictionary alloc] initWithObjectsAndKeys:values,@"recipients",@"Invitation",@"subject",@"ConnectWithMe",@"body", ir, @"item-content", nil];

[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

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

NSString *updateString = [update JSONString];

[request setHTTPBodyWithString:updateString];

NSLog(updateString);

OADataFetcher *fetcher = [[OADataFetcher alloc] init];

[fetcher fetchDataWithRequest:request

delegate:self

didFinishSelector:@selector(postUpdateApiCallResult:didFinish:)

didFailSelector:@selector(postUpdateApiCallResult:didFail:)];

[update release];

[values release];

[valueArray release];

[person release];

[request release];

I get the following response:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<error>

<status>401</status>

<timestamp>1328781555736</timestamp>

<request-id>5NMOQ1PDZR</request-id>

<error-code>0</error-code>

<message>[unauthorized]. OAU:rb1llp99ymv5|ac6b144f-0c2f-4378-af58-01fd564dd512|*01|*01:1328781530:l2WRgGGSR1Ap6SF+xdSsMSZiV60=</message>

</error>

Any idea on what is going wrong? Any pointers or sample you could provide for the invitations API would help us a lot.

Thanks,
Karthik.

Steven Citron-Pousty's picture
Joined: 08/02/2011
Thu, 02/09/2012 - 17:35

Greetings Karthik:
I am not an iOS dev but I think the problem is that the JSON you are posting does not have all the required fields filled in. Please look at the following table and make sure all the required fields have a value in your constructed JSON:
https://developer.linkedin.com/documents/invitation-api
Thanks
Steve