Search code examples
xmlhttprequestfetchbackendmultiplayerfacebook-instant-games

Load XMLHttpRequest from facebook Instant game returns empty result, even though I have just saved the data before getting it from server


The response from server returns empty result despite just saving data earlier in that contextID with success. Most time it returns the json data but sometimes in between it returns empty string leading to createNewGameAsync() function instead of going directly to populateFromBackend() function. I am creating backend from https://glitch.com/edit/#!/panoramic-tendency project on glitch.

loadData: function () {
    var contextID = FBInstant.context.getID();
    console.log('loadData from ' + contextID);
    FBInstant.player.getSignedPlayerInfoAsync(contextID)
    .then(function (signedPlayerInfo) {
        var url = 'https://panoramic-tendency.glitch.me' + '/get-match'
        var sig = signedPlayerInfo.getSignature();
        var method = 'POST'
        var payload = { 'signature': sig };
        return req(url, method, payload);
    })
    .then(function (result) {
        if (result.empty) {
            return this.createNewGameAsync();
        } else {
            return Promise.resolve(result.data);
        }
    }.bind(this)).then(function (backendData){  
            this.populateFromBackend(backendData);
    }.bind(this))
    .catch(function (error) {
        this.displayError(error);
    }.bind(this));

Solution

  • Solved. I was saving the FbInstant.Player.getPhoto() url as well in database. During encoding with getSignedPlayerInfoAsync() the signature generated was not valid format, and server couldn't decode it resulting in null value.