I am testing an instant games app and I ultimately want my bot to collect messaging_game_plays
events to log user data at the end of a play session. To allow messaging_game_plays
to be sent, I've been directed by this answer to canSubscribeBotAsync()
, and subscribeBotAsync()
from the Facebook Instant Games API v6.2. Following the API reference as a guide, I've built these canSubscribeBotAsync
and subscribeBotAsync
methods into the game's startup sequence. I also have my fbapp-config.json
set up with the proper
{
"instant_games": {
"bot": {
"subscription_type": "OPT_IN_DEV"
},
...
}
}
The problem I am facing is that canSubscribeBotAsync()
always returns false when I test the application and so I can't test the behavior when it returns true. canSubscribeBotAsync()
doesn't seem to return any other information when it returns false so I'm not exactly sure what is causing it to return this way.
I'm currently testing this problem by building and uploading my game to the facebook app, then moving it to the testing stage. Then I've been playing this game from my facebook account.
My question is: is there either some way to know why canSubscribtBotAsync()
returns false when it does? or does there exist a setting on my facebook app or personal facebook profile that might cause canSubscribeBotAsync()
to always return false?
I did note in the documentation for this method that any given player would only be prompted once. I haven't ever seen the opt-in prompt, but is there a chance the have-you-seen-it-already-flag has been tripped and it's returning false because of that?
I've had someone else try with their own account with the same behavior. I'm just now testing out some more possibilities, but I figured I would post this now in case anything looks out of place right away to anyone. I'm not expecting to find anything revolutionary, but I'll keep this question updated if I find anything else.
[edit] Tried with one more new facebook account and was able to see the logs of the game for a first time run. It gave a message to the user saying that the app would like to access public profile data and canSubscribeBotAsync()
returned false before the user clicked accept on the data prompt. After clicking "OK", the application resumed as usual.
The loading sequence:
Here is code I'm running with // rest of game setup logic
in place for the setup logic for a Phaser 3 game.
window.onload = () => {
console.log('FB Instant Games SDK Version: ' + FBInstant.getSDKVersion());
FBInstant.initializeAsync().then((value: boolean) => {
FBInstant.player.canSubscribeBotAsync().then((can_subscribe: boolean) => {
console.log((can_subscribe ? 'can' : 'cannot') + ' subscribe player to bot');
if (can_subscribe) {
FBInstant.player.subscribeBotAsync().then(function () {
console.log('subscribed player to bot');
}).catch(function (e: any) {
console.log('didn\'t subscribe player to bot. error: ' + e.message);
})
}
}).catch(function (e: any) {
console.log('couln\'t check if player can be subscribed. error: ' + e.message);
});
// rest of game setup logic
});
};
I always get the following output amidst the rest of the application output:
FB Instant Games SDK Version: 6.2
cannot subscribe player to bot <--(canSubscribeBotAsync returning false)
I have tried a number of different arrangements for the starting sequence, but I might not have this set up correctly?
This question looks to have a very similar problem, but the thread ends without a solution.
If anyone has any ideas or any bits of documentation that would point me in the right direction that would be greatly appreciated! I've done a fair bit of browsing myself but I've probably missed something along the way.
This is already above in a comment but I'll put it here as it was the solution to my problem!
It turned out that I was calling canSubscribeBotAsync
before startGameAsync
. Here is the order of calls that ended up working for me. This successfully prompted the user to opt in to bot messaging:
window.onload = () => {
FBInstant.initializeAsync().then((value: boolean) => {
FBInstant.startGameAsync().then(function () {
FBInstant.player.canSubscribeBotAsync().then((can_subscribe: boolean) => {
if (can_subscribe) {
FBInstant.player.subscribeBotAsync().then(function () {
// start game here
}).catch(function (e: any) {
// and here regardless
})
}
}).catch(function (e: any) {
// start game here too, launch the game!
});
// or start game here if the game should load underneath the popup
// this ended up not having good flow so we started the game above
});
});
};