1

I am trying to posting a tweet on twitter using iOS twitter.framework , somehow its not showing me any error when post request gets done, however its not posting anything on twitter!

Here's my code for

-(void)twitPost
{
    ACAccountStore *account = [[ACAccountStore alloc] init];
    ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
    NSArray *arrayOfAccounts = [account accountsWithAccountType:accountType];
    if (!arrayOfAccounts)
    {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"No Twitter Account" message:@"There are no Twitter accounts configured. You can add or create a Twitter account in the main Settings section of your phone device." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
        [alert release];
        return;
    }

    // Request access from the user to access their Twitter account
    [account requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error)
     {
         // Did user allow us access?
         if (granted == YES)
         {                 
             // Populate array with all available Twitter accounts
             NSArray *arrayOfAccounts = [account accountsWithAccountType:accountType];

             if ([arrayOfAccounts count] > 0)
             {
                 // Keep it simple, use the first account available
                 ACAccount *acct = [arrayOfAccounts objectAtIndex:0];

                 TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@"https://upload.twitter.com/1/statuses/update.json"] parameters:[NSDictionary dictionaryWithObject:@"This is a sample message!" forKey:@"status"] requestMethod:TWRequestMethodPOST];
                 [postRequest setAccount:acct];

                 // Perform the request created above and create a handler block to handle the response.
                 [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
                  {
                      if(error)
                      {
                          NSLog(@"Twitter Request failed with error: %@",[error localizedDescription]);
                      }else{
                          NSLog(@"Twitter response, HTTP response: %i", [urlResponse statusCode]);
                          NSLog(@"Message %@",[NSHTTPURLResponse localizedStringForStatusCode:[urlResponse statusCode]]);
                      }
                  }];
             }
         }
     }];
}

Inside the block, I am not getting any error, but I got to print this,

2013-09-12 19:51:40.103 MyApp[8380:21603] Twitter response, HTTP response: 410

2013-09-12 19:51:44.053 MyApp[8380:21603] Message no longer exists

It's not logged any error message!

Note,

1) I'd already configured a twitter account in the settings.

Update

I tried to link, https://upload.twitter.com/1.1/statuses/update.json in browser and it print the following JSON response!

{
    errors: [
    {
        message: "The Twitter REST API v1 is no longer active. Please migrate to API v1.1. https://dev.twitter.com/docs/api/1.1/overview.",code: 68
    } 
    ]
}

What's wrong? I am missing something? Is there a simple way to migrate to new API?

Hemang
  • 26,840
  • 19
  • 119
  • 186
  • Possible duplicate of [iOS 5 Twitter Framework: Tweeting without user input and confirmation (modal view controller)](http://stackoverflow.com/questions/9423447/ios-5-twitter-framework-tweeting-without-user-input-and-confirmation-modal-vie) – nalply Dec 04 '15 at 08:55

1 Answers1

0

You're using Twitter API version 1 which is deprecated.

The new one is documented here https://dev.twitter.com/docs/api/1.1

You may want to check third-party libraries such as STTwitter to ease you work.

nst
  • 3,862
  • 1
  • 31
  • 40