【发布时间】:2014-06-02 23:09:45
【问题描述】:
我想用状态 ID 回复 Twitter 状态。但我得到 http 响应 403。 这是我的代码。我可以发送第一条推文。我知道它的id。但是当我想用它的 id 回复第一条推文时,我得到 http 响应 403。我错了。
- (IBAction)btnSendToucUpInside:(id)sender {
__block NSDecimalNumber *tid;
__block int i = 0;
while (true) {
if (i == 0 || _birlestirilsinMi) {
urlParametres = [NSDictionary dictionaryWithObjectsAndKeys: [NSString stringWithFormat:@"%@", [self.twitArray objectAtIndex:0]], @"status", nil];
}else{
urlParametres = [NSDictionary dictionaryWithObjectsAndKeys: [NSString stringWithFormat:@"%@", [self.twitArray objectAtIndex:0]], @"status",[NSString stringWithFormat:@"%@",tid], @"in_reply_to_status_id",@"true", @"include_entities", nil];
}
TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@"https://api.twitter.com/1/statuses/update.json"] parameters:urlParametres requestMethod:TWRequestMethodPOST];
[postRequest setAccount:[twitAccountArray objectAtIndex:0]];
[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
{
if (responseData) {
i++;
NSDictionary *TWData = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
tid = TWData[@"id"];
NSLog(@"%@",tid);
//show status after done
NSString *output = [NSString stringWithFormat:@"HTTP response status: %i", [urlResponse statusCode]];
NSLog(@"Twiter post status : %@", output);
}
}];
if (i == _twitArray.count -1) {
break;
}
}
}
【问题讨论】:
-
403 表示未经授权,请仔细检查
[twitAccountArray objectAtIndex:0]中的内容可能是什么? -
@VincentG 我检查了。我发送没有循环的推文我可以发送每个帖子。
-
我调试了,我得到错误:响应数据中的重复状态
-
那么可能只是 Twitter 拒绝您发布两次相同的消息? :)
-
是的。我认为问题是while循环。因为while循环不等待响应。但我不知道另一种方式。你有关于这个@VincentG的任何解决方案