0

I am trying to integrate Twitter in my iOS application.

The application is expected to support iOS versions 6.x & 7.x.

I want to directly post a tweet once the user taps on a button in my UI, without again asking confirmation in SLComposeViewController alert.

I have gone through the following posts which say how to do that, problem being that they are both configured for iOS 5.x.

Stack Overflow Link 1

Stack Overflow Link 2

How exactly do I go about it?

Any help will be appreciated.

Community
  • 1
  • 1
footyapps27
  • 3,982
  • 2
  • 25
  • 42

2 Answers2

0

I see no differences from iOS 5.1 to iOS 6.0, neither iOS 6.1 to 7.0 for Twitter api.

Use the iOS 5 tutorials and check with alt+left mouse click to inform about deprications or modified functions if there are.

Maybe this will help.

Laszlo
  • 2,803
  • 2
  • 28
  • 33
0

In the two links you mentioned they are using Twitter Api v1. which is deprecated a long time ago: API V1 no longer function instead you should be using the V1.1 so the url to post a tweet will be https://api.twitter.com/1.1/statuses/update.json

In addition TWRequest is also deprecated in iOS 6.0 you should use SLRequest

Here is a simple code to do so:

- (void) sendTweetWithoutPromp:(NSString*) tweetText
{
    NSString *url = @"https://api.twitter.com/1.1/statuses/update.json";
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
    [params setObject:tweetText forKey:@"status"];

    ACAccountStore *accountStore = [[ACAccountStore alloc] init];
    ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

    [accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) {
        if(granted)
        {
            NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];
            if ([accountsArray count] > 0)
            {
                ACAccount *twitterAccount = [accountsArray objectAtIndex:0];

                SLRequest *postRequest = [SLRequest  requestForServiceType:SLServiceTypeTwitter requestMethod:TWRequestMethodPOST URL:[NSURL URLWithString:url] parameters:params ];

                [postRequest setAccount:twitterAccount];

                [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
                 {
                     NSString *output = [NSString stringWithFormat:@"HTTP response status: %i", [urlResponse statusCode]];
                     NSLog(@"output = %@",output);
                     dispatch_async( dispatch_get_main_queue(), ^{
                         if (error)
                         {

                         }

                     });
                 }];
            }
            else
            {
                NSLog(@"no Account in Settings");
            }
        }
    }];

}
MAB
  • 953
  • 7
  • 14