我现在正在使用PreactJS为facebook messenger开发webview。但现在问题是我没有任何解决方案来包含/实现在preactJS中添加Messenger Extensions。我做了如下,但chooseTownship
行动完全不起作用。请帮我解决一下。
chooseTownship = (e) => {
window.extAsyncInit = function() {
MessengerExtensions.getUserID(function success(uids) {
var psid = uids.psid;
var theUrl = "/webhooks/webview?fbUserId=" + psid + "&townshipId=" + e.target.name + "&townshipName=" + e.target.value;
fetch(url).then((response) => {
if (response.status === 200) {
MessengerExtensions.requestCloseBrowser(function success() {
}, function error(err) {
});
}
});
}, function error(err, errorMessage) {
console.log(errorMessage);
});
}
}
componentDidMount() {
const that = this;
const url = '/api/townships';
fetch(url).then((response) => {
if (response.status >= 400) {
throw new Error('Bad response from server');
}
return response.json();
}).then((data) => {
that.setState({
townships: data.townships
});
});
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.com/en_US/messenger.Extensions.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'Messenger'));
}