Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

twitter update using TWRequest gives 403 error

i'm using the following code to tweet in user's timeline using the iOS 5 twitter API

// Create an account store 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's 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've been using this method for more than a month now for testing the application and it used to work fine with no problems.

few weeks a goo it started to return a 403 error 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've searched a lot and could not find any solution or real cause to this problem.

a few notes to keep in mind that might help understanding the problem:

  • the application is used for testing which means that we used the twitter sharing and mentions a lot with other users.
  • the sharing content is not always the same so no duplication issue should occur as we were clearing the timeline frequently.

thanks

like image 867
Kassem Avatar asked Dec 04 '22 01:12

Kassem


1 Answers

The text you have been trying to tweet must be similar to what has been tweeted by you previously, hence you are getting this error. According to the documentation here, the same text cannot be posted more than once. enter image description here

EDIT:

It might also depend on the total number of tweets as mentioned in their website.

like image 118
Vidya Murthy Avatar answered Dec 28 '22 22:12

Vidya Murthy