错误:使用LinkedIn的REST Api for iOS / Like / Different和Comment

喜欢/不同和评论使用REST Api的iOS我使用下面的URL和模式喜欢networking发布。 我得到的答复是

“无法parsingJSON is-liked文件”

。 如果我在url中input'is-liked = true',我会收到以下消息:

“资源{更新}”中的未知字段{is-liked = true}“

。 我不知道什么是错的。 请帮忙。

这是我的代码:

updateKey= @"UNIU-c1028-5809277741404942336-SHARE"; NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://api.linkedin.com/v1/people/~/network/updates/key=%@/is-liked",updateKey]]; OAMutableURLRequest *request = [[OAMutableURLRequest alloc] initWithURL:url consumer:self.consumer token:self.token callback:nil signatureProvider:nil]; [request setValue:@"json" forHTTPHeaderField:@"x-li-format"]; [request setHTTPMethod:@"PUT"]; 

好吧,我要把这个留给有类似问题的人。 罪魁祸首是HTTPBody不是追加is-Liked键的“ true ”。

所以我增加了真的手动喜欢,并做了诀窍。

 NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://api.linkedin.com/v1/people/~/network/updates/key=%@/is-liked",updateKey]]; OAMutableURLRequest *request = [[OAMutableURLRequest alloc] initWithURL:url consumer:self.consumer token:self.token callback:nil signatureProvider:nil]; [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; [request setHTTPBodyWithString:@"true"];// <-this is the magic wand! [request setHTTPMethod:@"PUT"]; 

我有同样的问题,我花了很多小时使用NSMutableURLRequest结合AFNetworking的AFHTTPRequestOperation后find了解决scheme。 试试这个代码:

  NSString *stringRequest = @"https://api.linkedin.com/v1/people/~/shares?oauth2_access_token=ACCESS_TOKEN&format=json"; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:stringRequest]]; [request setHTTPMethod:@"PUT"]; [request setHTTPBody:[@"true" dataUsingEncoding:NSUTF8StringEncoding]]; //set true or false according to like-unlike request. [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"result: %@", responseObject); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog([error localizedDescription]); }]; [operation start];