Error: Like/Unlike and Comment using LinkedIn REST

2019-08-31 16:44发布

Like/Unlike and Comment using REST Api for iOS I'm using the following url and pattern for liking a network post. I get the response as

"Can not parse JSON is-liked document"

. If I make 'is-liked=true' in the url I get the message:

"Unknown field {is-liked=true} in resource {Update}"

. 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"];

2条回答
男人必须洒脱
2楼-- · 2019-08-31 17:09

I had the same problem, i found the solution after spending many hours using NSMutableURLRequest combined with AFHTTPRequestOperation of AFNetworking. 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];
查看更多
狗以群分
3楼-- · 2019-08-31 17:10

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.

So I added true for is-Liked manually and that did the trick.

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"];
查看更多
登录 后发表回答