Hello,
In my cordova app I use the native facebook plugin to handle all the authorization token and then I call the Login With Facebook SDK. I’m not using the JS SDK because it does not works inside a cordova app (ONLY social login does not work)
The login works perfectly in fact the user is created on the db. However the response of the REST API is a JSON inside an HTML page, so I’ve to parse the HTML to extract user information.
This is the way I call the REST API
var xhr = new XMLHttpRequest();
xhr.open("POST", "https://api.backendless.com/v1/users/social/facebook/sdk/login", true);
xhr.setRequestHeader('application-id', Backendless.applicationId);
xhr.setRequestHeader('secret-key', Backendless.secretKey);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.setRequestHeader('application-type', 'REST');
xhr.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log(this);
}
};
var body = {
accessToken: params.accessToken,
fieldsMapping: params.facebookFieldsMapping
};
xhr.send(JSON.stringify(body));
This is the response
<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
window.setTimeout( function ()
{
if(window.opener)
window.opener.postMessage( JSON.stringify( {"birthday":"11/13/1997","image":null,"lastLogin":"Fri Dec 09 12:43:52 UTC 2016","gender":"male","created":"Fri Dec 09 12:43:52 UTC 2016","ownerId":"XXXXXXXXXX","__meta":"{\"relationRemovalIds\":{},\"selectedProperties\":[\"birthday\",\"image\",\"gender\",\"created\",\"ownerId\",\"__updated__meta\",\"password\",\"name\",\"___class\",\"id\",\"updated\",\"objectId\",\"email\"],\"relatedObjects\":{}}","user-registered":true,"name":"XXXXXXXXXXXXXXXXX","___class":"Users","id":"XXXXXXXXXXXXXX","user-token":"XXXXXXXXXXXXXXXXXXXXXX","updated":null,"objectId":"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX","email":"XXXXXXXXXXXXXXXXXXXXX"} ), 'null' );
else
parent.postMessage( JSON.stringify( {"birthday":"11/13/1997","image":null,"lastLogin":"Fri Dec 09 12:43:52 UTC 2016","gender":"male","created":"Fri Dec 09 12:43:52 UTC 2016","ownerId":"XXXXXXXXXXXXXXXXXXXXXXXXXXXX","__meta":"{\"relationRemovalIds\":{},\"selectedProperties\":[\"birthday\",\"image\",\"gender\",\"created\",\"ownerId\",\"__updated__meta\",\"password\",\"name\",\"___class\",\"id\",\"updated\",\"objectId\",\"email\"],\"relatedObjects\":{}}","user-registered":true,"name":"XXXXXXXXXXXXXXXX","___class":"Users","id":"XXXXXXXXXXXXX","user-token":"XXXXXXXXXXXXXXXXXXXXX","updated":null,"objectId":"XXXXXXXXXXXXXXXXXXXXXXXX","email":"XXXXXXXXXXXXXXXXXXX"} ), 'null' );
}, 0 );
</script>
</body>
</html>"
Any idea how to fix?