Start a new topic

Kinvey + Titanium[Backbone] + Facebook

Hey,



i am facing a problem (small thing, i guess) using Facebook integration with the backbone/Titanium Libary.







At the moment my example code looks like this:

function onFacebookClick(e) {



var user = new Kinvey.Backbone.User();



var promise = user.connect('facebook', {

appId : Facebook.appid,

success : function(model, response, options) {

console.log("Facebook Success");

},

error : function(error){

alert("error");

}

});

}



The problem ist, that neither the success or the error handler are executed. (But the app opens the facebook register window etc. without any problem)



Expected:

After successfull login with my facebook account data and returned to the app, it should "fire" the success handler, so that i cann move forward.



Any hint/idea would be great.



Best,

Nico

Gurmukh: 


It seems like the post 2 above this one from Mark seems to resolve the issue, so the standard titanium implementation would likely be the best route to go.


Thanks,

Hi,


I've got the same problem, I think email verification is disabled by default, and I'm getting nothing from success or error, should I just default to the titanium implementation?


Thanks

Ah thanks for that Marc! :smile:



I'll post my complete code later on here, maybe it could help other Ti Dev's to avoid the problems/questions that i have.



For the login you can just use the login method, no need to go through connect:



```

var user = new Kinvey.Backbone.User();

var promise = user.login({

_socialIdentity: {

facebook: {

access_token: ''

}

}

});

```
Hmm ok i am working on that.



Obtaining the token by the native module isn't a big deal at all.

To be honest, i'm a little bit confused:





Register:

User--> get Facebook token --> "per hand" create user on Kinvey passing the socialIdentity --> Email for verification is send || everything works fine and as expected.



Login:

If the user opens the application and is logged in to facebook - how could i login him? Just than call the "connect" method of Titanium? Cause connect is just to "connect" a user to social identity once, i thought?



Claryfication would be nice :smile:

Nico, I am able to reproduce now. Turns out this is caused by two things:



1. Your app enforces email verification when new users are created. When using the social connect, after getting the access token from the Facebook dialog, a new user is created with solely that token. Hence no e-mail address is part of this, therefore the request fails as an e-mail address is required.

2. The library has a bug where failures like the ones above are not passed through to the error handler. For now, you can circumvent this by using promises:

```

var promise = user.connect('facebook', {

appId: Facebook.appid

}).then(function(model, response, options) {

console.log("Facebook Success");

}, function(error) {

alert("error");

});

```



The 1. point above is a tricky problem. Right now, you could use Titanium’s Facebook module manually to obtain the user data (including the email address), and then calling `user.save()` manually as well:



```

// Obtain the user data from Facebook through Titanium’s Facebook module.

// Then, create the Kinvey user manually.

var user = new Kinvey.Backbone.User({

email: '',

_socialIdentity: {

facebook: {

access_token: ''

}

}

});

var promise = user.save();

```
Hey,

i am building for ios (and android, but didn't test that ) - i think i configurated everything on facebook for the application and the oauth table in the kinvey backend.





Emulator. Reading through your reply, I guess you’re on iOS. Can you give me the details I asked for in my last reply, so I can try and replicate in the same environment as you are developing on? Thanks!
Hmm did you try it in Simulator and/or on Device?



Thanks,

Nico
I tried to run the above snippet in the latest Titanium (3.2.2), and I am able to successfully obtain the Facebook access token and user data.



Which platform are you building for? Did you configure your Facebook app at all at developers.facebook.com?
Login or Signup to post a comment