ios - Facebook在ios问题中使用firebase登录
问题描述
let credential = FacebookAuthProvider.credential(withAccessToken: FBSDKAccessToken.current().tokenString)
//authenticate with firebase
Auth.auth().signInAndRetrieveData(with: credential) { (authResult, error) in
if (error == nil) {
self.fetchProfile(firebaseID: (authResult?.user.uid)!)
}
}
我收到这个错误。请帮我解决这个问题。我用过这个https://firebase.google.com/docs/auth/ios/facebook-login?authuser=1
Error Domain=FIRAuthErrorDomain Code=17999 "An internal error has occurred, print and inspect the error details for more information." UserInfo={error_name=ERROR_INTERNAL_ERROR, NSLocalizedDescription=An internal error has occurred, print and inspect the error details for more information., NSUnderlyingError=0x604000846cf0 {Error Domain=FIRAuthInternalErrorDomain Code=3 "(null)" UserInfo={FIRAuthErrorUserInfoDeserializedResponseKey={
code = 403;
errors = ({
domain = global;
message = "Requests to this API identitytoolkit method google.cloud.identitytoolkit.v1.AuthenticationService.SignInWithIdp are blocked.";
reason = forbidden;
});
message = "Requests to this API identitytoolkit method google.cloud.identitytoolkit.v1.AuthenticationService.SignInWithIdp are blocked.";
status = "PERMISSION_DENIED";
}}}}
解决方案
步骤 1. 添加 pod 如下
pod 'FBSDKCoreKit'
pod 'FBSDKLoginKit'
pod 'FBSDKShareKit'
步骤 2. 添加到您的 Info.plist 文件
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>fb<Your App id></string>
</array>
</dict>
</array>
<key>FacebookAppID</key>
<string><Your App id></string>
<key>FacebookDisplayName</key>
<string><Your DisplayName></string>
<key>FirebaseAppDelegateProxyEnabled</key>
<false/>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fb-messenger-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
</array>
步骤 3. 添加到您的 AppDelegate
import FBSDKCoreKit
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
//Facebook
FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
}
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
let handled = FBSDKApplicationDelegate.sharedInstance().application(app, open: url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String!, annotation: options[UIApplicationOpenURLOptionsKey.annotation])
return handled
}
第 4 步:将其添加到您的视图控制器
import FBSDKLoginKit
class LoginScreenViewController: UIViewController, FBSDKLoginButtonDelegate {
override func viewDidLoad() {
super.viewDidLoad()
btn_Facebook.addTarget(self, action: #selector(handleCustomFBLogin), for: .touchUpInside)
}
///FACEBOOK LOGIN
func handleCustomFBLogin(sender:UIButton!){
FBSDKLoginManager().logIn(withReadPermissions: ["email", "public_profile"], from: self) { (result, err) in
if(err != nil){
print("Custom FB Login Failed")
return
}
//print(result?.token.tokenString)
self.showEmailAddress()
}
}
func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!){
if(error != nil){
print(error)
return
}
print("Successfully Logged in using facebook")
showEmailAddress()
}
func showEmailAddress(){
let accesstoken = FBSDKAccessToken.current();
guard let accessTokenString = accesstoken?.tokenString else {return}
FBSDKGraphRequest(graphPath: "/me", parameters: ["fields" : "id, name, first_name, last_name, email, birthday, picture"]).start { (connection, result, err) in
if(err != nil){
print("Failed to start GraphRequest", err ?? "")
return
}
print(result ?? "")
}
}
func loginButtonDidLogOut(_ loginButton: FBSDKLoginButton!){
print("Logged out of Facebook")
}
}
推荐阅读
- python - Dash 中的连接树图
- javascript - 合并 2 个对象数组,但如果属性具有相同的值,则合并数组
- grails - 覆盖 DefaultGroovyMethods 方法
- angular - 模板未在数组的父可观察对象中更新
- javascript - Javascript confirm popup do nothing on cancel click
- python - api中不存在数据时处理Keyerror
- javascript - 如何使用本地 Json 文件中的密钥作为 JavaScript 函数中的变量?
- c# - 发布 SQLCLR 程序失败,因为它不受信任,即使它位于 sys.trusted_assemblies 中
- subroutine - 在 YottaDB 中实现 MUMPS 子例程的问题
- docusignapi - DocuSign 移动设备屏幕上的电子记录和签名披露协议