2013-11-22 51 views
0

喜欢/不同和评论使用REST Api的iOS 我使用以下URL和模式喜欢网络发布。我得到的答复为错误:喜欢/不同和评论使用LinkedIn REST API的iOS

"Can not parse JSON is-liked document"

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

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

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

这里是我的代码:

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

回答

1

好了,我要离开这对于具有类似问题的人。罪魁祸首是HTTPBody不是为is-Liked密钥添加'true'。

因此,我添加了is-Liked手动,并做了诀窍。

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

我有同样的问题,我发现使用NSMutableURLRequestAFHTTPRequestOperation的AFNetworking联合花费几个小时后的溶液。试试这个代码:

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