在ios 7中使用twitter登录
我正在做登录功能。 其中-在ios 7中使用twitter登录,twitter,ios7,twitter-oauth,social-framework,acaccount,Twitter,Ios7,Twitter Oauth,Social Framework,Acaccount,我正在做登录功能。 其中- 用户将提供twitter电子邮件id进行登录,如果登录成功,我的应用程序将引导用户进入我的应用程序的内部屏幕 如果用户已通过用户的设备ios设置配置twitter帐户。我的应用程序从那里获取用户的电子邮件id,并将导航 进入我的应用程序的第二个屏幕 若用户并没有从ios设置中配置twitter帐户,那个么,若用户点击“我的应用程序登录”屏幕上的“使用twitter登录”按钮,它将 将用户导航到twitter页面,用户必须从该页面提供 电子邮件id(twitter id
我怎样才能做到这一点。提前感谢。首先,您无法使用iOS7框架或twitter的本机API从twitter的API获取用户电子邮件地址。
如果您想获得用户电子邮件地址,可以要求用户手动输入。这就是推特用户在API文档中所说的。对于第2点和第3点,这里是使用iOS7方式的示例代码
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) // check Twitter is configured in Settings or not
{
self.accountStore = [[ACAccountStore alloc] init]; // you have to retain ACAccountStore
ACAccountType *twitterAcc = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[self.accountStore requestAccessToAccountsWithType:twitterAcc options:nil completion:^(BOOL granted, NSError *error)
{
if (granted)
{
self.twitterAccount = [[self.accountStore accountsWithAccountType:twitterAcc] lastObject];
NSLog(@"Twitter UserName: %@, FullName: %@", self.twitterAccount.username, self.twitterAccount.userFullName);
[self getTwitterEmail]; // here you can ask user to enter email address. Its up to you how you ask user about it. Either in alert View or in Text Field.
}
else
{
if (error == nil) {
NSLog(@"User Has disabled your app from settings...");
}
else
{
NSLog(@"Error in Login: %@", error);
}
}
}];
}
else
{
NSLog(@"Not Configured in Settings......"); // show user an alert view that Twitter is not configured in settings.
}
首先,无论是使用iOS7框架还是twitter的本机API,都无法从twitter的API获取用户电子邮件地址。
如果您想获得用户电子邮件地址,可以要求用户手动输入。这就是推特用户在API文档中所说的。对于第2点和第3点,这里是使用iOS7方式的示例代码
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) // check Twitter is configured in Settings or not
{
self.accountStore = [[ACAccountStore alloc] init]; // you have to retain ACAccountStore
ACAccountType *twitterAcc = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[self.accountStore requestAccessToAccountsWithType:twitterAcc options:nil completion:^(BOOL granted, NSError *error)
{
if (granted)
{
self.twitterAccount = [[self.accountStore accountsWithAccountType:twitterAcc] lastObject];
NSLog(@"Twitter UserName: %@, FullName: %@", self.twitterAccount.username, self.twitterAccount.userFullName);
[self getTwitterEmail]; // here you can ask user to enter email address. Its up to you how you ask user about it. Either in alert View or in Text Field.
}
else
{
if (error == nil) {
NSLog(@"User Has disabled your app from settings...");
}
else
{
NSLog(@"Error in Login: %@", error);
}
}
}];
}
else
{
NSLog(@"Not Configured in Settings......"); // show user an alert view that Twitter is not configured in settings.
}
你在这方面做了什么吗?@damm108:谢谢你的回复,我使用了旧的twitter api,但我想从ios标准库中完成。可能吗?谢谢,这在ios标准框架中是不可能的,请使用,这是一个很好的工具,它完成了你想做的所有工作,因为它与Accounts.framework.Social.frameworkLet让我知道它是否与你一起工作。你在这方面做了什么吗?@damm108:谢谢你的回复,我使用了旧的twitter api完成了这项工作,但我想从ios标准库中完成这项工作。可能吗?谢谢,这在ios标准框架中是不可能的,请使用,这是一个很好的工具,它可以完成你想做的所有工作,因为它与Accounts.framework Social.frameworkLet让我知道它是否与你一起工作
userFullName
目前只适用于Facebook
。userFullName
目前只适用于Facebook
。