hello, im trying to login with facebook using swift 3, but an error is occurring before building the app on Xcode
thats a sample of my code with the error showing in attached file :
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) → Bool {
let result = FBSDKApplicationDelegate.sharedInstance().application(application, open: url, sourceApplication: sourceApplication, annotation: annotation)
if result {
let token = FBSDKAccessToken.current()
let fieldsMapping = [
“id” : “facebookId”,
“name” : “name”,
“user_gender”: “gender”,
“email”: “email”
]
backendless.userService.loginWithFacebookSDK(
token,
fieldsMapping: fieldsMapping,
response: { (user: BackendlessUser!) → Void in
print(“user: (user)”)
},
error: { (fault: Fault!) → Void in
print(“Server reported an error: (fault)”)
})
// backendless?.userService.loginWithFacebookSDK(
// token,
// fieldsMapping: fieldsMapping,
// response: { (user: BackendlessUser!) → Void in
// print(“user: (user)”)
// },
// error: { (fault: Fault!) → Void in
// print(“Server reported an error: (fault)”)
// })
}
return result
}
Please try:
backendless!.userService.login(
withFacebookSDK: token,
permissions: ["user_friends", "email", "public_profile", "contact_email"],
fieldsMapping: fieldsMapping,
response: { (user: BackendlessUser?) -> Void in
print("user: \(user!.email)\n[\(user!.retrieveProperties())]")
self.validUserTokenSync()
},
error: { (fault: Fault?) -> Void in
print("Server reported an error: \(fault)")
})
You can see our swift 3 sample project in attachment.
TestS3FacebookSDKLogin.zip (20.18MB)
hey again,
i did exactly what you proposed, i dont have errors anymore, but the facebook data is not being added to my “users” table in backendless
do you have any idea why ?
Please, update the latest Backendless SDK (pod 3.0.41 release), and try again.
If this issue will persist, give us your appId here - we will investigate the problem with your app.
EDIT: you wrote: “but the facebook data is not being added to my “users” table in backendless”. Is this with our sample or with your app?
that’s my app, if u can check it please
Provide your appId here or to support@backendless.com.
Also, please, clarify: are you able to reproduce the problem with OUR sample project?
There is our swift 2.3 project in attachment. You could set your appId , secretKey and Info.plist options URL Types->URL Schemrs and FacebookAppID:
http://support.backendless.com/public/attachments/c4392aa559449124f009ce0ccc9e2ec0.png</img>
with your Facebook application Id, which you have set as Social Settings:
http://support.backendless.com/public/attachments/62b3b72411c954a8d49d4eb85965b0a3.png</img>
and check it with your Backendless app.
TestEasyLogin.zip (19.26MB)
i was testing it on the simulator, the informations are being added to the table correctly,
but i have no idea why the facebookid is being added in the email column
shouldn’t the email be added instead ?
Use permissions:
backendless.userService.loginWithFacebookSDK(
token,
permissions: ["user_friends", "email", "public_profile", "contact_email"],
fieldsMapping: fieldsMapping,
response: { (user: BackendlessUser!) -> Void in
print("user: \(user) \n[\(user.retrieveProperties())]")
if user.isUserRegistered() {
print("NEW REGISTATION")
}
self.validUserTokenSync()
},
error: { (fault: Fault!) -> Void in
print("Server reported an error: \(fault)")
})
Maybe you created your Facebook account with phone (without email) or deny a public usage of email. Check your Facebook account.
i checked my facebook account, my email is public
Provide your appId, we will check this issue with your app.
all is working perfectly thank you,
i still have one more question if possible : how can i check in my appdelegate if the user is logged in to facebook or not ?
hello again,
i’ve been trying to put my users informations in the table “users” on backendless useing SWIFT3
but its not working
thats the code im using :
let user: BackendlessUser = BackendlessUser()
user.email = self.emailUser.text
user.password = self.passwordUser.text
self.backendless.userService.registering(user)