2

I want to send a tweet directly from my iPhone app without showing TWTweetComposeViewController pop up

Also i want to get all followers is there a way to do it from twitter framework on the ios5 or should i use another api!

If I have to use another api can u specify a great api for me ? because all the apis i found on the internet was so old.

Thanks in advance

Ilanchezhian
  • 17,426
  • 1
  • 53
  • 55
coctile
  • 83
  • 2
  • 5

3 Answers3

3

You can use TWRequest for programatically posting tweets from my app, if you are using iOS 5.0 and up. Posting tweets is quite straightforward and there is no need for an external framework or anything.

You need the #import <Twitter/Twitter.h>. You retrieve the twitter account from the iPhone account store (you could check if there are multiple accounts) and then you use the account to post the request.

Here is an example of a method for posting a tweet with an image.

- (void)shareTwitterImage:(UIImage *)image
{
    ACAccountStore *accountStore = [[ACAccountStore alloc] init];
    ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

    [accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error)
     {
         if(granted)
         {
             NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];

             if ([accountsArray count] > 0)
             {
                 ACAccount *twitterAccount = [accountsArray objectAtIndex:0];

                 TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@"https://upload.twitter.com/1/statuses/update_with_media.json"] parameters:[NSDictionary dictionaryWithObject:self.textViewOutlet.text forKey:@"status"] requestMethod:TWRequestMethodPOST];

                 [postRequest addMultiPartData:UIImagePNGRepresentation(image) withName:@"media" type:@"multipart/png"];
                 [postRequest setAccount:twitterAccount];

                 [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
                  {
                      //show status after done
                      NSString *output = [NSString stringWithFormat:@"HTTP response status: %i", [urlResponse statusCode]];
                      NSLog(@"Twiter post status : %@", output);
                  }];
             }
         }
     }];
}
AndrejKolar
  • 284
  • 1
  • 9
1

There are quite a few options:

Well, on iOS 6, there is the Apple Social framework, and you can use SLComposeViewController to post to Twitter as well as Facebook and Sina Weibo, here are the docs. TWTweetComposeViewController has been deprecated, devices running iOS 6 will have to run into backward compatibility -- so avoid that.

There is also ShareKit, however I do not generally recommend it, its messy and bloated. Lastly there is the Oauth Library in iOS... create a consumer key and secret key. You can also call the Twitter API with TWRequest.

That's all of them I can think of.

Rohan.

MCKapur
  • 9,127
  • 9
  • 58
  • 101
0

In case you plan on integrating TwitterKit by Twitter to perform the tweets via your custom twitter app then this might help you.

https://stackoverflow.com/a/28602749/1740354

With the same methods you can get the followers list by using the following API https://dev.twitter.com/rest/reference/get/followers/list

Hope it helps.

Community
  • 1
  • 1
Vijay Tholpadi
  • 2,135
  • 1
  • 15
  • 20