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;
        }
    }
}
7
  • 403 means unauthorized, double check what is in [twitAccountArray objectAtIndex:0] maybe? Jun 1, 2014 at 12:43
  • @VincentG i checked. i sent tweets without loop i can sent each post.
    – renis
    Jun 1, 2014 at 13:21
  • i debugged and i get error: duplicate status in responsedata
    – renis
    Jun 1, 2014 at 14:14
  • Then maybe simply Twitter reject that you post twice the same message? :) Jun 2, 2014 at 9:55
  • Yes. I think problem is while loop. Because while loop don't wait response. But i don't know another way. have you any solution about this @VincentG
    – renis
    Jun 2, 2014 at 10:54

1 Answer 1

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) {...}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.