2013-02-16 48 views
3

澄清如果您只想使用iOS提供的社交API(帳戶框架),您是否可以讓用戶使用其Facebook或Twitter帳戶登錄您的應用?
如果是,那麼你和userid(或名稱,twittername,facebook名稱)一起使用以確保(在服務器端)他們是誰。iOS社交api可以使用Facebook或Twitter來驗證用戶(讓用戶登錄到您的應用)嗎?

更具表現力的解釋 我有一個很難理解背後的第三方註冊和登錄的集成工作流/邏輯原生的iOS(或Android)應用程序, 因此iOS中有一箇中央存儲,保持用戶嘰嘰喳喳(或Facebook)的憑據和應用程序可以調用API來獲取用戶Twitter的ID,到目前爲止這麼好,但如果我想與後端服務器交談並證明用戶是誰,他們聲稱只是擁有用戶ID是不夠的,
我錯過了什麼?

我的問題是如果您的後端服務器沒有證明您是憑據,您如何驗證用戶?

+0

也許使用Oauth(2)?! – Till 2013-02-16 14:52:36

+0

@Till iOS提供oAuth api嗎?或者你說你無法使用iOS提供的API驗證用戶,你需要使用oAuth? – Ali 2013-02-17 12:17:43

回答

0

您可以使用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); 
    } 
}]; 

在這一點上,你可以使用OAuth憑證在accountStore,您可以發送到您的服務器的任何服務器端的交互想要與Facebook。

相關問題