Why FBInstant.chooseAsync method not sending game play request to friend?

1.8k views Asked by At

I am trying to send game play request to my Facebook friend using FBinstant.chooseAsync method. But no request is sending to my friend and I am not getting any data at callback after calling this method.

Here is my game code:

FBInstant.initializeAsync() .then(function() { 

    console.log("FBInstant.initializeAsync complete"); 
    console.log("FBInstant.startGameAsync complete"); 

    FBInstant.startGameAsync().then(function() { 
    
        console.log("FBInstant.startGameAsync complete"); 
        console.log("FBInstant.startGameAsync context : " + FBInstant.context.getID()); 

        FBInstant.context.chooseAsync() .then(function (e) { 

            console.log("FBInstant.context.chooseAsync complete"); 
            console.log(e); 
        }); 
    }); 
});
3

There are 3 answers

0
leolu On

it seems that you have to call updateAsync in the resolve function of chooseAsync, you may try something like flowing:

FBInstant.context.chooseAsync() .then(function () { 
    window.FBInstant.updateAsync(
    {
      action: "CUSTOM",
      cta: "Join The Fight",
      template: "join_fight",
      image: base64Picture, //this should be source data of your share picture in 
                            //base64! you can parse your picture to base64 use  
                            //'https://www.base64-image.de'
      text: "X just invaded Y's village!",
      data: {
        myReplayData: "..."
      },
      strategy: "IMMEDIATE",
      notification: "NO_PUSH"
    }).then(function() {
      window.FBInstant.quit();
    }).catch(function(err){
        console.error(err);
    });
}); 
0
Evgeny Kharetski On

At first, FBInstant.context.chooseAsync() opens a context selection dialog (see API Reference v6.2). At second, why you use FBInstant.startGameAsync() twice? Try this code:

FBInstant.initializeAsync() .then(function() {

    // Start loading game assets here 
    console.log("FBInstant.initializeAsync complete"); 

    // Finished loading. Start the game 
    FBInstant.startGameAsync().then(function() { 

        console.log("FBInstant.startGameAsync complete"); 
        console.log("FBInstant.startGameAsync context : " + FBInstant.context.getID()); 

        FBInstant.context.chooseAsync() .then(function () { 
            console.log("FBInstant.context.chooseAsync complete");
        }); 

    }); 
});
0
Keeves Dev On

You have to add a method to call FBInstant.updateAsync() to update the context. It will send the message to friend chosen in context.

You can use updateAsync only once per session in context(i.e: You can't keep calling updateAsync method repeatedly, It will only work 1st time, not on later requests), until your friend responds in the context.

However if you change the context or reopen the context, then you can post one update again, irrespective whether your friend responded to it(like: using reminders to friend to remind them to respond).

Your method can be sonething like this:

updateContext(){
var updateData = {
        action: 'CUSTOM',
        intent: 'REQUEST',
        cta: actionButton,
        template: "join_fight",
        image: "base64 image data",
        //data would be like: "data:image/png;base64,lkhkfhjvajsdbka....",
        text: 'Message to be posted',
        data: { myReplayData: 'any data to be attatched' },
        strategy: 'IMMEDIATE',
        notification: 'NO_PUSH'
    };
    FBInstant.updateAsync(updateData);
}