How to access the Callback Data from Native Facebook Foreign Code.

I have been able to reproduce all the code of Facebook Native Login with Foreign Code … however there is something that I am missing, the callback success should contain the return that came from the Facebook library, however the return comes with an empty object. And from what I saw there is not an onSuccess function, only a simple this.Resolve. Can someone help me with this?

Thanks in advance.

Hi!

I need to see the code in question to be able to help out :slight_smile:

Hi Vegard,

Take a look at this code:

MainView.ux

The result on: returns an empty object

function login() {
      FacebookLogin.login().then(function(result) {
        console.log("Login successful");
      }, function(err) {
        console.log("Login failed: " + err);
      });
    }

looking into https://github.com/fusetools/fuse-samples/blob/feature-NativeFacebookLogin/Samples/NativeFacebookLogin/FacebookLogin/FacebookLogin.uno

At line 108

public class AccessToken
	{
		extern(iOS) ObjC.Object _token;
		extern(Android) Java.Object _token;
		public extern(iOS) AccessToken(ObjC.Object token)
		{
			_token = token;
		}
		public extern(Android) AccessToken(Java.Object token)
		{
			_token = token;
		}
	}

it seens that this class is used as a onSuccess return ( I think )… but i tried to get access to _token variable without success.

Hey!

Uno object properties are not automatically available in JavaScript.

I suggest that you add a NativeFunction to the FacebookLoginModule that takes the token as an argument.

The token argument to the NativeFunction will be of type Fuse.Scripting.External on the Uno side, which is a wrapped Uno object that is passed in from JavaScript. The External has an Object property to get the inner wrapped object, so to get back the AccessToken object, you’d do something like (args[0] as Fuse.Scripting.External).Object as AccessToken.

Once you have the AccessToken you can use foreign code to get its properties and return them back to JavaScript.

I’ve created an issue to improve this sample by showing how to do this.

As a code example this is ok… I’m trying to do this because this is the only missing method to publish my app.

But, as a real example logic for facebook, the Login function must result the data provided from facebook like clientid, access token, user data, etc. Don’t you think?

Yes, agreed!

The hope is that the example is useful as starting point for using third-party SDKs but it is perhaps a little too minimal if considered as an example of using the Facebook SDK specifically.

Hi’!

I’ve got the same problem. How to solve it ?

Hi Thomas, in the last example NativeFacebookLogin you can get the accessToken as string. Time ago I modified a little the module to return also the facebookId, email and name here is the link https://github.com/jesusmartinoza/fuse-samples/blob/feature-NativeFacebookLogin/Samples/NativeFacebookLogin/MainView.ux