質問

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"];
役に立ちましたか?

解決

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

他のヒント

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];
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top