问题
I use OAuthStarter Kit for accessing the LinkedIn API. I get an access token successfully for the permissions.
rw_ns
r_basicprofile
r_fullprofile
It is possible to get the profile details as well as to share only comments and while sharing URL or image or description etc... I using following code:
-(void)postUpdate
{
NSURL *url = [NSURL URLWithString:@"http://api.linkedin.com/v1/people/~/shares"];
OAMutableURLRequest *request =
[[OAMutableURLRequest alloc] initWithURL:url
consumer:[self getConsumer]
token:self.accesstoken
callback:nil
signatureProvider:nil];
NSDictionary *update = [[NSDictionary alloc] initWithObjectsAndKeys:
[[NSDictionary alloc]
initWithObjectsAndKeys:
@"anyone",@"code",nil], @"visibility",
@"title goes here",@"title",
@"comment goes here", @"comment",
@"description goes here",@"description",
@"www.google.com",@"submitted-url",
@"http://economy.blog.ocregister.com/files/2009/01/linkedin-logo.jpg",@"submitted-image-url",
nil];
[request setValue:@"json" forHTTPHeaderField:@"x-li-format"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
NSString *updateString = [update JSONString];
[request setHTTPBodyWithString:updateString];
[request setHTTPMethod:@"POST"];
OADataFetcher *fetcher = [[OADataFetcher alloc] init];
[fetcher fetchDataWithRequest:request
delegate:self
didFinishSelector:@selector(postUpdateApiCallResult:didFinish:)
didFailSelector:@selector(postUpdateApiCallResult:didFail:)];
}
But I get a response error as follows:
2012-10-09 18:27:29.906 SocialConnectTest[9460:19a03] data {
"errorCode": 0,
"message": "Invalid xml {Expected elements 'post-network-update@http://api.linkedin.com/v1 id@http://api.linkedin.com/v1 visibility@http://api.linkedin.com/v1 comment@http://api.linkedin.com/v1 attribution@http://api.linkedin.com/v1 content@http://api.linkedin.com/v1 private-message@http://api.linkedin.com/v1 share-target-reach@http://api.linkedin.com/v1' instead of 'submitted-url@http://api.linkedin.com/v1' here in element share@http://api.linkedin.com/v1}",
"requestId": "W2G7WJDHOJ",
"status": 400,
"timestamp": 1349787449685
}
And I don't know what the problem is. Can anyone please help me solving this?
回答1:
i fixed it. The problems is in the post parameters
- As per the documentation of Linked in api,if we use JSON in request body then keys of post params must be in camel case, while in xml "-" seperated key names are used.
- Share parameter like submittedUrl , subsubmittedImageUrl , description,title **etc. must be values of key called **content.
so i modified the code as follows..
-(void)postUpdateHERE
{
NSURL *url = [NSURL URLWithString:@"http://api.linkedin.com/v1/people/~/shares"];
OAMutableURLRequest *request =
[[OAMutableURLRequest alloc] initWithURL:url
consumer:[self getConsumer]
token:self.accesstoken
callback:nil
signatureProvider:nil];
NSDictionary *update = [[NSDictionary alloc] initWithObjectsAndKeys:
[[NSDictionary alloc]
initWithObjectsAndKeys:
@"anyone",@"code",nil], @"visibility",
@"comment goes here", @"comment",
[[NSDictionary alloc]
initWithObjectsAndKeys:
@"description goes here",@"description",
@"www.google.com",@"submittedUrl",
@"title goes here",@"title",
@"http://economy.blog.ocregister.com/files/2009/01/linkedin-logo.jpg",@"submittedImageUrl",nil],@"content",
nil];
[request setValue:@"json" forHTTPHeaderField:@"x-li-format"];
[request setValue:@"application/xml" forHTTPHeaderField:@"Content-Type"];
NSString *updateString = [update JSONString];
[request setHTTPBodyWithString:updateString];
[request setHTTPMethod:@"POST"];
OADataFetcher *fetcher = [[OADataFetcher alloc] init];
[fetcher fetchDataWithRequest:request
delegate:self
didFinishSelector:@selector(postUpdateApiCallResult:didFinish:)
didFailSelector:@selector(postUpdateApiCallResult:didFail:)];
}
now the code works for me..
来源:https://stackoverflow.com/questions/12801187/cant-share-using-oauth-starter-kit-for-linkedin