我正在尝试使用FBinstant.chooseAsync方法将游戏请求发送到我的Facebook朋友。但是没有请求发送给我的朋友,并且调用此方法后,我在回调中没有任何数据。
这是我的游戏代码-
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);
});
});
});
答案 0 :(得分:0)
首先,public class MyActivity extends AppCompatActivity {
...
private int selectedHourOfDay, selectedMinuteOfDay;
...
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView textView = findViewById(R.id.text_view);
Calendar calendar = Calendar.getInstance();
selectedHourOfDay = calendar.get(Calendar.HOUR_OF_DAY);
selectedMinuteOfDay = calendar.get(Calendar.MINUTE);
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new TimePickerDialog(MyActivity.this, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker timePicker, int hour, int minute) {
textView.setText(hour + "h " + minute + "m");
selectedHourOfDay = hour;
selectedMinuteOfDay = minute;
}
}, selectedHourOfDay, selectedMinuteOfDay, false).show();
}
});
}
...
}
打开上下文选择对话框(请参见API Reference v6.2)。
第二,为什么还要两次使用FBInstant.startGameAsync()?尝试以下代码:
FBInstant.context.chooseAsync()
答案 1 :(得分:0)
似乎您必须在selectAsync的resolve函数中调用updateAsync,您可以尝试以下流程:
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);
});
});
答案 2 :(得分:0)
您必须添加一个方法来调用FBInstant.updateAsync()来更新上下文。它将消息发送给上下文中选择的朋友。
在上下文中,每个会话只能使用一次updateAsync(即:您不能继续重复调用updateAsync方法,它只能在第一次使用,而不能在以后的请求上使用),直到您的朋友在上下文中做出响应为止。
但是,如果您更改上下文或重新打开上下文,则无论您的朋友是否响应,都可以再次发布一个更新(例如:使用提醒朋友来提醒他们响应)。
您的方法可以像这样:
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);
}