澄清如果您只想使用 iOS 提供的社交 API(帐户框架),您可以让用户使用他们的 facebook 或 twitter 帐户登录您的应用吗?
如果是,那么您将什么与用户 ID(或名称、推特名称、Facebook 名称)一起使用以确保(在服务器端)他们是谁。
更具表现力的解释
我很难理解 native iOS(或 Android)应用程序中第 3 方注册和登录集成背后的工作流程/逻辑,
所以在 iOS 中有一个中央存储,可以保存用户的推特(或 Facebook)凭据,应用程序可以调用 API 来获取用户的推特 ID,到目前为止还不错,但是如果我想与后端服务器交谈并证明用户是他们自称的人只是拥有用户 ID 是不够的,
我错过了什么吗?
我的问题是如果用户不向您提供凭据,您如何通过后端服务器对用户进行身份验证?
最佳答案
您可以使用 ACAccountStore 进行身份验证。感谢http://blogs.captechconsulting.com/blog/eric-stroh/ios-6-tutorial-integrating-facebook-your-applications对于下面的大部分代码。
self.accountStore = [[ACAccountStore alloc]init];
ACAccountType *FBaccountType= [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSString *key = @"987654"; //put your own key from FB here
NSDictionary *dictFB = //use the ACAccountStore ACFacebookPermissionsKey to help create your dictionary of permsission you'd like to request, such as the users email, writing on the wall, etc.
[self.accountStore requestAccessToAccountsWithType:FBaccountType options:dictFB completion: ^(BOOL granted, NSError *e) {
if (granted) {
NSArray *accounts = [self.accountStore accountsWithAccountType:FBaccountType];
//it will always be the last object with SSO
self.facebookAccount = [accounts lastObject];
} else {
//Fail gracefully...
NSLog(@"error getting permission %@",e);
}
}];
此时,您可以访问 accountStore 中的一个 oauth token ,您可以将该 token 发送到您的服务器,以便与 facebook 进行任何服务器端交互。
关于ios - iOS 社交 api 是否可用于使用 facebook 或 twitter 对人员进行身份验证(让人们登录到您的应用程序)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14910864/