簡體   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