【发布时间】:2014-02-06 08:46:50
【问题描述】:
我想将 twitter 集成到我的应用程序中,主要用于登录目的,我想像下面的案例一样实现它
- 检查是否有任何 Twitter 帐户已与手机使用反向身份验证相关联
- 如果没有关联帐户,请使用一些用于 twitter 的 OAuth 库并使用该库进行身份验证
任何人都知道任何现有的库/框架做同样的事情吗?谢谢
P.S : 支持的最低 iOS 版本为 iOS6
【问题讨论】:
标签: ios twitter twitter-oauth
我想将 twitter 集成到我的应用程序中,主要用于登录目的,我想像下面的案例一样实现它
任何人都知道任何现有的库/框架做同样的事情吗?谢谢
P.S : 支持的最低 iOS 版本为 iOS6
【问题讨论】:
标签: ios twitter twitter-oauth
您可以使用以下代码:(如果在设置中没有找到帐户,那么这会将您的应用程序带到设备的设置屏幕):
- (IBAction)loginWithTwitterBtn:(id)sender
{
if ([TWTweetComposeViewController canSendTweet])
{
//yes user is logged in
accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
// Request access from the user to use their Twitter accounts.
[accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error)
{
// Did user allow us access?
if (granted == YES)
{
// Populate array with all available Twitter accounts
NSArray *arrayOfAccounts = [accountStore accountsWithAccountType:accountType];
ACAccount *acct = [arrayOfAccounts objectAtIndex:0];
// Set the cell text to the username of the twitter account
NSString *userID = [[acct valueForKey:@"properties"] valueForKey:@"user_id"];
}
}];
}
else
{
//show tweeet login prompt to user to login
TWTweetComposeViewController *viewController = [[TWTweetComposeViewController alloc] init];
//hide the tweet screen
viewController.view.hidden = YES;
//fire tweetComposeView to show "No Twitter Accounts" alert view on iOS5.1
viewController.completionHandler = ^(TWTweetComposeViewControllerResult result) {
if (result == TWTweetComposeViewControllerResultCancelled) {
[self dismissModalViewControllerAnimated:NO];
}
};
[self presentModalViewController:viewController animated:NO];
//hide the keyboard
[viewController.view endEditing:YES];
}
}
//*******************
【讨论】:
https://github.com/aryansbtloe/LoginViaSocialMedias
这是一个示例项目,用于向您的 ios 应用程序添加通过 facebook、twitter、google plus 和四方支持登录。
【讨论】: