自作のiOSアプリからTwitter APIを使用していて気づいたこと

ACAccountStore *account = [[ACAccountStore alloc]init]; ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; __block NSString *message = textInInglish; [account requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted , NSError *error){ if(granted == YES) { NSArray *arrayOfAccounts = [account accountsWithAccountType:accountType]; if( [arrayOfAccounts count] > 0){ ACAccount *twitterAccount = [arrayOfAccounts lastObject]; NSLog(@"twitterid= %@",twitterAccount.username); NSURL *requestURL = [NSURL URLWithString:@"https://api.twitter.com/1.1/statuses/update.json"]; NSDictionary *parameters = @{@"status": message}; SLRequest *postRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodPOST URL:requestURL parameters:parameters]; postRequest.account = twitterAccount; [postRequest performRequestWithHandler: ^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { NSInteger statusCode = urlResponse.statusCode; if(statusCode != 200){ NSLog(@"Error"); } NSLog(@"send"); NSLog(@"error=%@",[error localizedDescription]); }]; } }else{ NSLog(@"Handle failure"); } }];

とやっていて、一回目は成功してちゃんとツィッターに投稿されていることを確認できた。次に同じ文字列を投稿すると、403 forbiddenのレスポンスが返された。

Twitter APIのヘルプには、「This code is used when requests are being denied due to update limits」(出所:https://dev.twitter.com/docs/error-codes-responses)とあるが、limitsに引っかかるほどの投稿はしていない。
で、同じ文字列の投稿を行うと403のエラーが返ってくることに気づいた。文字列を変えると成功する。ふーん。。