Unable to login with facebook for ionic 3 app

Hi , I am building an ionic 3 app with cordova support.
I have integrated the facebook login using cordova plugin (https://github.com/jeduan/cordova-plugin-facebook4) , and it works fine.
Now I am using backendless 4 to persist this fetched facebook user details.
Ref doc : https://backendless.com/docs/js/doc.html#users_facebook_login
My code looks like this

facebookLoginCordova() {
 this.facebook.login(['public_profile', 'user_friends', 'email',])
 .then(res => {
 var userId = "/" + res.authResponse.userID + "?fields=name,first_name,last_name,email,picture"
 this.facebook.api(userId,['public_profile']).then(res => { 
 this.user = res
 this.loginFBBackendless()
 })
 console.log('Logged into Facebook!', res)
 }).catch(e => console.log('Error logging into Facebook', e)); 
 }
 
 loginFBBackendless() {
 var facebookFieldsMapping = { 
 email : 'email',
 name : 'name',
 first_name: ' first_name',
 last_name : 'last_name'
 }
 Backendless.UserService.loginWithFacebookSdk(facebookFieldsMapping,true) 
 .then( res => {
 this.message = "Successfully saved user to backendless"
 console.log("Successfully saved user to backendless")
 })
 .catch( function( error ) {
 this.message = "Error while saving user to backendless"
 console.log("Error while saving user to backendless")
 }); 
 }

I am unable to persist the user , there is no error either. I tested the Backendless connectivity with the TestTable

Backendless.Data.of('TestTable').save({ foo: 'bar' }) 

and this worked and i can see the table entries in the backendless console.
Am I doing something wrong or is it issue with backendless 4 for ionic.

Hi Bhavya,

Have you configured your Backendless app per the instructions from here (see the “Login with Facebook setup” section):
https://backendless.com/docs/js/doc.html#dynanchor11

Regards,
Mark

Hi Mark ,
As per the link provided above , up on adding the api.backendless.com into the App Domains field , facebook console threw this error while saving

App domains must match the domain of the Facebook Web Games URL (https), Mobile Site URL, Unity Binary URL, Site URL or Secure Page Tab URL. Please correct these domains: api.backendless.com.

I added the https://api.backendless.com. to valid OAUTH redirects list , but the changes dint help.

Regards,
Bhavya.

Hi, I was not able to reproduce the problem in facebook application you’ve attached.
This domain should correspond to URI set to the ‘Site URL’. You need to add a platform ‘website’ and add https://api.backendless.com as a site url. Please go attentively through the instructions to configure your facebook application. Then paste facebook appid and secret to social settings located in Manage > App settings.

To see how login through social networks should be implemented - you may generate a sample for JS. Codegeneration tab > Language JS > select facebook login.

It’s a working example, if you face any difficulties - please track exceptions and post it here

Best regards

Hi Anton ,
Thank you for the help ! I added the site url in ‘website’ platform and the error is gone.
The backendless facebook login using Backendless.UserService.loginWithFacebook() works like a charm.

But my actual use case is that , for my android app I should login through cordova plugin facebook sdk (https://github.com/jeduan/cordova-plugin-facebook4) and persist the logged in user to the backendless.

So now I replaced Backendless.UserService.loginWithFacebook() with Backendless.UserService.loginWithFacebookSdk() and followed the steps mentioned here (https://backendless.com/docs/js/doc.html#users_facebook_login > Integration API ) and ran the ionic project on android emulator.

My code looks like this :

var facebookFieldsMapping = {
id :'userId',
email : 'email',
name : 'name',
first_name : 'first_name',
last_name : 'last_name'
}
this.message = authRes.authResponse.accessToken
Backendless.UserService.loginWithFacebookSdk(facebookFieldsMapping ,true)
.then( res => {
this.message = "Successfully saved user to backendless"
console.log("Successfully saved user to backendless")
})
.catch( err => {
this.message = "Error while saving user to backendless"
console.log("Error while saving user to backendless" + err)
});

After successfully login with cordova facebook plugin , when Backendless.UserService.loginWithFacebookSdk(fieldsMapping,true) was invoked ,
it internally made a POST call to backendless that resulted in an error with error code 8002.

POST [url=https://api.backendless.com///users/social/facebook/login/]https://api.backendless.com/<APP_ID>/<API_KEY>/users/social/facebook/login/<APP_ID>[/url];
{
"authResponse": {
"accessToken": "<access token>",
"userID": "&lt;userId&gt;",
"expiresIn": 5742,
"signedRequest": "&lt;signed url&gt;"
},
"status": "connected",
"fieldsMapping": {
"id": "userId",
"email": "email",
"name": "name",
"first_name": "first_name",
"last_name": "last_name"
}
}

Response:
status : 404

{
"code": 8002,
"message": "Could not parse request with message: , status code 404, headers POST /&lt;APP_ID&gt;/&lt;API_KEY&gt;/users/social/facebook/login/&lt;APP_ID&gt;",
"errorData": {
 
 



}
}

NOTE : I made no changes to my social setting in backendless console for this . But on facebook dev console I added "http://<my-ip>:8100/" to the valid oauth url list.

Can you help me out .

Regards,
Bhavya.

For some reason JS SDK using a non-existing route for facebook login. I’ve created an internal task with id BKNDLSS-16440 to fix this issue. We’ll roll out an updated version of JS SDK and will notify you here ASAP.

Thanks for your report and sorry for the inconvenience

Best Regards