我正在尝试使用Send to Messenger插件,但如果我尝试使用其他FB用户的页面ID和我的Messenger应用ID初始化它,则不会呈现它。这个用户已经允许我管理他的页面,所以我从其中一个获取页面ID(他选择哪个)。 Messenger文档中没有关于此场景的内容..
我是这样做的:
流速:
我的messenger机器人尚未发布(仍处于开发阶段)。
我尝试过的事情没有结果: - 试用我在我的应用中创建的测试用户 - 尝试在我的应用程序设置中为用户提供Tester角色
代码:
<html>
<body>
<script>
// If user is logged in to FB get his pages
function statusChangeCallback(response) {
if (response.status === 'connected') {
fetchPages();
}
}
// Login listener
function checkLoginState() {
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
}
// Initialize FB
window.fbAsyncInit = function() {
FB.init({
appId: 'XXXX',
cookie: true,
xfbml: true,
version: 'v2.6'
});
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
};
// Load the SDK asynchronously
(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.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
function fetchPages() {
FB.api('/me/accounts', function(response) {
if (response && response.data && !response.error) {
// Get all pages managed by the logged in user
var pages = response.data;
var pageIds = [];
pageList.innerHTML = '';
// User selects one of these pages, let's say first one
var selectedPage = pages[0];
var pageSelector = document.getElementById('pageSelector');
pageSelector.addEventListener("click", function() {
// Create the Send to Messenger element with
// messenger_app_id: my app's ID
// page_id: ID of the selected page
var sendToMessengerWrapper = document.getElementById('sendToMessengerWrapper');
sendToMessengerWrapper.innerHTML = '';
var plugin = document.createElement('div');
plugin.setAttribute('class', 'fb-send-to-messenger');
plugin.setAttribute('messenger_app_id', 'XXXX');
plugin.setAttribute('page_id', selectedPage.id);
plugin.setAttribute('data-ref', 'ref');
plugin.setAttribute('color', 'blue');
plugin.setAttribute('size', 'standard');
sendToMessengerWrapper.appendChild(plugin);
// Re-render the button - this only worked the for page directly connected to my app.
FB.XFBML.parse(document.getElementById('sendToMessengerWrapper'));
});
}
});
}
</script>
<!-- Notice the permissions I am requesting -->
<fb:login-button id="logInBtn" scope="manage_pages,pages_messaging,pages_messaging_phone_number" onlogin="checkLoginState();">
</fb:login-button>
<input type="button" id="pageSelector" value="Connect page"/>
<!-- Plugin button should be rendered inside this element -->
<div id="sendToMessengerWrapper"></div>
</body>
答案 0 :(得分:3)
问题是我的应用的webhook没有订阅该页面。如果未通过Messenger产品的应用设置或通过Graph API进行订阅,则不会显示该按钮。