I’m writing an app that will feature SSO via Twitter.
So far, using the built-in functionality in iOS 5, I’ve been able to come up with something like this using internet search results:
if ([TWTweetComposeViewController class])
{
TWTweetComposeViewController *tweeter = [[TWTweetComposeViewController alloc] init];
[tweeter setInitialText:@"Greg can't figure out Twitter in iOS 5"];
[self presentModalViewController:tweeter animated:YES];
}
How would I get the Twitter user’s “User ID” (@gregkrsak, in my case), if I wanted to store it for later use?
The
TWTweetComposeViewControllerdoes not give you access to the user’s Twitter user ID, just as theMFMailComposeViewControllerdoes not give you access to the user’s email address.Fortunately, you can retrieve the user’s Twitter user IDs (there may be more than one), but it takes a little more work. You will need to create an
ACAccountStoreobject, query it for all TwitterACAccountobjects, and then extract theaccount.usernameproperty for each. In the process, the user will see an alert asking if he wants to give the app access to his Twitter accounts.It’s not hard to do all this, and a great resource is the WWDC 2011 session video (and slides) on Twitter.