【问题标题】:Error: Like/Unlike and Comment using LinkedIn REST Api for iOS错误:喜欢/不喜欢和评论使用适用于 iOS 的 LinkedIn REST Api
【发布时间】:2014-10-13 23:11:16
【问题描述】:

使用适用于 iOS 的 REST Api 点赞/取消赞和评论 我正在使用以下网址和模式来点赞网络帖子。我得到的回应是

"无法解析 JSON is-like 文档"

。如果我在网址中输入“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"];

【问题讨论】:

    标签: ios iphone rest linkedin


    【解决方案1】:

    好的,我将把这个留给有类似问题的人。罪魁祸首是 HTTPBody 没有为 is-Liked 键附加“true”。

    所以我手动为 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"];
    

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题,我在使用 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];
      

      【讨论】:

        猜你喜欢
        • 2013-05-26
        • 2016-03-24
        • 2020-10-07
        • 2016-11-13
        • 1970-01-01
        • 2016-11-09
        • 1970-01-01
        • 2013-11-05
        • 1970-01-01
        相关资源
        最近更新 更多