Updating twitter using TWRequest gives error 403

I am using the following code for tweets in user timeline using iOS 5 twitter API

// Create an account storage object. ACAccountStore * accountStore = [[ACAccountStore alloc] init];

// Create an account type that ensures Twitter accounts are retrieved. ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; // Request access from the user to use their Twitter accounts. [accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) { if(granted) { // Get the list of Twitter accounts. NSArray *accountsArray = [accountStore accountsWithAccountType:accountType]; // For the sake of brevity, we'll assume there is only one Twitter account present. // You would ideally ask the user which account they want to tweet from, if there is more than one Twitter account present. // Grab the initial Twitter account to tweet from. ACAccount *twitterAccount = [accountsArray objectAtIndex:buttonIndex]; // Create a request, which in this example, posts a tweet to the user timeline. // This example uses version 1 of the Twitter API. // This may need to be changed to whichever version is currently appropriate. TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@"http://api.twitter.com/1/statuses/update.json"] parameters:[NSDictionary dictionaryWithObject:@"hello this is a tweet" forKey:@"status"] requestMethod:TWRequestMethodPOST]; // Set the account used to post the tweet. [postRequest setAccount:twitterAccount]; // Perform the request created above and create a handler block to handle the response. [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { NSString *output = [NSString stringWithFormat:@"%i", [urlResponse statusCode]]; [self performSelectorOnMainThread:@selector(TweetStatus:) withObject:output waitUntilDone:NO]; }]; } }]; 

I have been using this method for over a month now to test the application, and it worked perfectly without problems.

A few weeks ago, he began to return error 403 in the following method.

 [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { NSString *output = [NSString stringWithFormat:@"%i", [urlResponse statusCode]]; [self performSelectorOnMainThread:@selector(TweetStatus:) withObject:output waitUntilDone:NO]; }]; 

it gives the following error:

 Error Domain=NSURLErrorDomain Code=-1012 "The operation couldn't be completed. (NSURLErrorDomain error -1012.)" UserInfo=0x1f8b3250 {NSErrorFailingURLKey=http://api.twitter.com/1/statuses/update.json, NSErrorFailingURLStringKey=http://api.twitter.com/1/statuses/update.json, NSUnderlyingError=0x1ed19f90 "The operation couldn't be completed. (kCFErrorDomainCFNetwork error -1012 

I searched a lot and could not find a solution or a real reason for this problem.

A few notes to keep in mind to help understand the problem:

  • the app is used for testing, which means we used Twitter sharing and we mention a lot with other users.
  • general content is not always the same, so the duplication problem does not arise, since we often clear the schedule.

thanks

+4
source share
3 answers

I have been using this method for over a month now to test the application, and it worked perfectly without problems.

I think the problem is right there. this account you are testing can be marked as a spammer from other people.

If you use a different account or another phone, and the code works, then this is my friend’s only explanation.

Good luck.

+6
source

The text you tried to tweet should be similar to what you tweeted earlier, so you get this error. According to the documentation here , the same text cannot be sent more than once. enter image description here

EDIT:

It may also depend on the total number of tweets mentioned on their website.

+7
source

I noticed that you are using the following URL to post a tweet from your user:

http://api.twitter.com/1/statuses/update.json

This uses version 1.0 of the Twitter API, which is deprecated and will slowly stop working over the next few months.

Instead, you should try using

https://api.twitter.com/1.1/statuses/update.json (the last change in the Twitter API was . Now you can only use HTTPS.)

It will indicate the latest version of the API.

+4
source

All Articles