[英]Error: Like/Unlike and Comment using LinkedIn REST Api for iOS
Like/Unlike and Comment using REST Api for iOS I'm using the following url and pattern for liking a network post. 使用REST Api for iOS的“喜欢/不喜欢和评论”我正在使用以下url和模式来喜欢网络帖子。 I get the response as
我得到的回应
"Can not parse JSON is-liked document"
“无法解析JSON赞文档”
. 。 If I make 'is-liked=true' in the url I get the message:
如果我在网址中输入“ is-liked = true”,则会收到以下消息:
"Unknown field {is-liked=true} in resource {Update}"
“资源{Update}中的未知字段{is-liked = true}”
. 。 I don't know what must be wrong.
我不知道那一定是错的。 Please help.
请帮忙。
Here's my code: 这是我的代码:
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"];
Alright, I'm leaving this for people having a similar issue. 好吧,我把这个留给有类似问题的人。 The culprit was the HTTPBody that was not appending '
true
' for is-Liked
key. 罪魁祸首是没有为
is-Liked
键添加' true
'的HTTPBody。
So I added true for is-Liked manually and that did the trick. 因此,我为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"];
I had the same problem, i found the solution after spending many hours using NSMutableURLRequest combined with AFHTTPRequestOperation of AFNetworking . 我遇到了同样的问题,在将NSMutableURLRequest与AFNetworking的AFHTTPRequestOperation结合使用了数小时后,我找到了解决方案。 Try this code:
试试这个代码:
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];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.