本机 iOS 应用程序:如何使用 iOS 5 检索 Twitter 用户 ID?
我正在编写一个应用程序,该应用程序将通过 Twitter 实现 SSO。
到目前为止,使用 iOS 5 中的内置功能,我已经能够使用互联网搜索结果得出类似的结果:
if ([TWTweetComposeViewController class])
{
TWTweetComposeViewController *tweeter = [[TWTweetComposeViewController alloc] init];
[tweeter setInitialText:@"Greg can't figure out Twitter in iOS 5"];
[self presentModalViewController:tweeter animated:YES];
}
如何获取 Twitter 用户的“用户 ID”(在我的例子中为 @gregkrsak),如果我想存储它以供以后使用?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
TWTweetComposeViewController
不允许您访问用户的 Twitter 用户 ID,就像MFMailComposeViewController
不允许您访问用户的电子邮件地址一样。幸运的是,您可以检索用户的 Twitter 用户 ID(可能不止一个),但这需要更多的工作。您需要创建一个
ACAccountStore
对象,在其中查询所有 TwitterACAccount
对象,然后提取每个对象的account.username
属性。在此过程中,用户将看到一条警告,询问他是否想让应用程序访问他的 Twitter 帐户。做到这一切并不难,Twitter 上的 WWDC 2011 会议视频(和幻灯片)是一个很好的资源。
The
TWTweetComposeViewController
does not give you access to the user's Twitter user ID, just as theMFMailComposeViewController
does 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
ACAccountStore
object, query it for all TwitterACAccount
objects, and then extract theaccount.username
property 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.