I ran the facebook auth and it works well, but When i go to the firebase authentication tab, the user is not there
Here's the code
import UIKit
import FBSDKCoreKit
import FBSDKLoginKit
import FirebaseFacebookAuthUI
class ViewController: UIViewController {
#IBOutlet weak var name: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let loginButton = FBSDKLoginButton()
loginButton.readPermissions = ["public_profile", "email"]
// Optional: Place the button in the center of your view.
loginButton.center = view.center
view.addSubview(loginButton)
}
func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!) {
if let error = error {
print(error.localizedDescription)
return
} else {
let credential = FacebookAuthProvider.credential(withAccessToken: FBSDKAccessToken.current().tokenString)
print(credential)
Auth.auth().signIn(with: credential) { (user, error) in
if let _ = error {
return
}
self.name.text = "\(user)"
print("user is sign in")
}
}
}
}
Do i need to do any extra configuration?
Related
Hellos developers,
who anyone can help me with one issue , I try to make a Facebook login and after that I want to go to another view.
But I can't make that happens, could some one can help me with that?
I put my code below:
import UIKit
import FBSDKLoginKit
import FBSDKCoreKit
class ViewController: UIViewController , LoginButtonDelegate{
func loginButton(_ loginButton: FBLoginButton, didCompleteWith result: LoginManagerLoginResult?,
error: Error?) {
loginButton.permissions = ["public_profile","email"]
if error != nil {
print("Something is Wrong... \(String(describing: error))")
return
}
print("Succesful loged in !")
}
func loginButtonDidLogOut(_ loginButton: FBLoginButton) {
loginButton.titleLabel?.text = "Adios"
print("GoodBye ")
}
override func viewDidLoad() {
super.viewDidLoad()
let loginButton = FBLoginButton()
loginButton.center = view.center
view.addSubview(loginButton)
loginButton.permissions = ["public_profile", "email"]
loginButton.addTarget(self, action: #selector(getUserFBInfo), for: .touchUpOutside)
}
#objc func getUserFBInfo(){
print("se logro ")
let token = AccessToken.current
if token == AccessToken.current {
performSegue(withIdentifier: "secondActivity", sender: self)
}else if token!.isExpired{
print("no sucede nada")
}
}
}
If you want the LoginButtonDelegate to call your delegate function (e.g. loginbutton:didCompleteWithResult:error:), remember to assign the delegate to the FBLoginButton.
In the above code, since the delegate is the UIViewController itself (not a must), you will need to add loginButton.delegate = self
I am trying to do Sign In with Facebook/Firebase Swift authentication, and I'm at the point where there's a functioning button. I am trying to run something that performs a segue once the login is complete, but I have not been successful in my tries.
func viewDidLoad(){
let loginButton = LoginButton(readPermissions: [ .publicProfile, .email])
loginButton.center = view.center
view.addSubview(loginButton)
if let accessToken = AccessToken.current {
print("signed in")
}
}
func loginButtonDidLogOut(_ loginButton: LoginButton){
print("logged out of fb")
}
func loginButton(_ loginButton: LoginButton!, didCompleteWith result: LoginResult!, error: Error!) {
if error != nil {
print(error)
return
}
I have been struggling with this following program execution which is currently I am doing in Xcode 8 and Swift 3...its just a simple login program but whenever the app runs the console simply prints the error "Could not successfully update network info during initialization" even before clicking the login button and the solutions are very less and none of them worked for me.
import UIKit
import FBSDKCoreKit
import FBSDKLoginKit
class ViewController: UIViewController, FBSDKLoginButtonDelegate {
#IBOutlet weak var btnButton: FBSDKLoginButton!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!)
{
if error == nil
{
print("login Successful")
self.configureFacebook()
}
else
{
print("error\(error!)")
}
}
func loginButtonDidLogOut(_ loginButton: FBSDKLoginButton!)
{
let loginManager: FBSDKLoginManager = FBSDKLoginManager()
loginManager.logOut()
print("logout successful")
}
func configureFacebook()
{
btnButton.readPermissions = ["public_profile", "email", "user_friends"];
btnButton.delegate = self
}
}
I am trying to perform a FacebookLogin using Firebase and the Facebook Login button, but I keep getting this
error:Facebook login was cancelled.
2016-04-01 19:08:15.721
biblos[778:408049] Warning: Attempt to present
on
whose view is not in the
window hierarchy!
User logged out...
Facebook login was cancelled.
2016-04-01 19:08:53.675 biblos[778:408049] Warning: Attempt to present
on
whose view is not in the
window hierarchy!
My ViewController code is as follows:
import UIKit
import Firebase
import FBSDKCoreKit
import FBSDKLoginKit
class ViewController: UIViewController, FBSDKLoginButtonDelegate {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
var loginButton = FBSDKLoginButton()
loginButton.readPermissions = ["public_profile", "email", "user_friends"]
loginButton.center = self.view.center
loginButton.delegate = self
self.view.addSubview(loginButton)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Facebook Login
func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!)
{
let ref = Firebase(url: "https://biblos-thebookapp.firebaseio.com")
let facebookLogin = FBSDKLoginManager()
facebookLogin.logInWithReadPermissions(["email"], handler: {
(facebookResult, facebookError) -> Void in
if facebookError != nil {
print("Facebook login failed. Error \(facebookError)")
} else if facebookResult.isCancelled {
print("Facebook login was cancelled.")
} else {
let accessToken = FBSDKAccessToken.currentAccessToken().tokenString
ref.authWithOAuthProvider("facebook", token: accessToken,
withCompletionBlock: { error, authData in
if error != nil {
print("Login failed. \(error)")
} else {
print("Logged in! \(authData)")
}
})
}
})
}
func loginButtonDidLogOut(loginButton: FBSDKLoginButton!)
{
print("User logged out...")
}
}
This method is deprecated. Try to use logInWithReadPermissions:fromViewController:handler: instead and pass your UIViewController or nil (topmost will be used).
https://developers.facebook.com/docs/reference/ios/current/class/FBSDKLoginManager/
I followed the tutorial here to integrate Facebook login on my application. I can login successfully with that button, but it doesn't call my method didCompleteWithResult upon login to fetch user details. This is my code.
import UIKit
class LoginViewController: UIViewController, FBSDKLoginButtonDelegate {
#IBOutlet weak var loginBtn: FBSDKLoginButton!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func configureFacebook()
{
loginBtn.readPermissions = ["public_profile", "email", "user_friends"];
loginBtn.delegate = self
}
func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!){
FBSDKGraphRequest.init(graphPath: "me", parameters: ["fields":"first_name, last_name, picture.type(large)"]).startWithCompletionHandler { (connection, result, error) -> Void in
let strFirstName: String = (result.objectForKey("first_name") as? String)!
let strLastName: String = (result.objectForKey("last_name") as? String)!
let strPictureURL: String = (result.objectForKey("picture")?.objectForKey("data")?.objectForKey("url") as? String)!
print("Welcome, \(strFirstName) \(strLastName)")
//self.profilePic.image = UIImage(data: NSData(contentsOfURL: NSURL(string: strPictureURL)!)!)
}
}
func loginButtonDidLogOut(loginButton: FBSDKLoginButton!)
{
}
}
Option-1
I dont know where you add this method in here I submit answer in dynamically , customize your self..
override func viewDidLoad() {
super.viewDidLoad()
configureFacebook() // if you want here add here or else if you want to load the facebook details in Button action add there
// Do any additional setup after loading the view.
}
func configureFacebook()
{
loginBtn.readPermissions = ["public_profile", "email", "user_friends"];
loginBtn.delegate = self
}
option-2
if you add the delegate in directly in your viewcontroller do like for example