0

I want to reply to twitter status with status id. but i get http response 403. Here my code. I can sent first tweet. I get it's id. But when i want sent reply to first tweet with it's id i get http response 403. What is my wrong.

 - (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;
        }
    }
}
renis
  • 171
  • 7
  • 16

1 Answers1

0

You are sending repeatedly the same message to twitter, your loop being erratic and not using properly your twitArray variable. Make sure to use twitArray when building your TWRequest instances. You need something like:

for (NSString *twit in twitArray) {
    ...
    urlParametres = @{ @"status" : twit }
    ...
}

instead of using [self.twitArray objectAtIndex:0] at each iteration...


Also take care of TWRequest : TWRequest is deprecated in iOS 6.0 - what can I use instead?


Kinda off-topic, but while(true) + break is a really bad practice, almost as bad as using goto, you definitely should use something like:

for (NSString *twit in twitArray) {...}

Or if you need a reversed order:

for (NSString *twit in twitArray.reverseObjectEnumerator) {...}
Community
  • 1
  • 1
Vincent Guerci
  • 14,379
  • 4
  • 50
  • 56