繁体   English   中英

错误:使用iOS版LinkedIn REST Api赞/不赞和评论

[英]Error: Like/Unlike and Comment using LinkedIn REST Api for iOS

使用REST Api for iOS的“喜欢/不喜欢和评论”我正在使用以下url和模式来喜欢网络帖子。 我得到的回应

“无法解析JSON赞文档”

如果我在网址中输入“ is-liked = true”,则会收到以下消息:

“资源{Update}中的未知字段{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"];

好吧,我把这个留给有类似问题的人。 罪魁祸首是没有为is-Liked键添加' true '的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"];

我遇到了同样的问题,在将NSMutableURLRequestAFNetworkingAFHTTPRequestOperation结合使用了数小时后,我找到了解决方案。 试试这个代码:

    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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM