I want to add a simple limited Twitter function to my app: a user of the app enters his Twitter username and password and tweet text, and presses a button and the tweet is sent. My app can process notification of success or failure (for example, if the password or username was invalid).
I promise I've watched a hundred YouTube videos and scoured the 'Net. 开发者_StackOverflow中文版Has anyone seen a simple tutorial or presentation to allow me to do this?
If all you want is one-way posting to Twitter, you might be better off using ShareKit, which is a little simpler than the alternatives people have mentioned so far and also supports other services, such as Facebook.
You can use this engine that integrates the Twitter API with Objective C:
MGTwitterEngine
And a good tutorial here:
Tutorial
I used this engine, and its overall very easy to use.
For those in 2015 looking for an answer for iOS it is the social framework
#import <Social/Social.h>
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
UIImage *img = someImage;
SLComposeViewController *tweetSheet = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText: @"my tweet text change it to your needs"];
[tweetSheet addImage:img];
[tweetSheet addURL:[NSURL URLWithString:@"http://yoursite.com"]];
[self presentViewController:tweetSheet animated:YES completion:nil];
}
Check bengottlieb / Twitter-OAuth-iPhone for a complete implementation of the API.
You have to implement O-Auth and can't simply manage your users' password and login yourself anymore. Twitter-Oauth-iPhone includes MGTwitterEngine by Matt Gemmell, OAuthConsumer Framework by Jon Crosby, OAuth-MyTwitter by Chris Kimpton, etc. in a relatively simple programming interface.
精彩评论