[英]Facebook webview fails when shared
编辑
我正在尝试在我的facebook Messenger机器人的webview中获取用户ID。 它在移动设备上可以正常运行,但在台式机(网络)上无法运行。 事实并非如此。
Messenger 2.1发行声明给出以下报价:
桌面对Extensions SDK的支持:这项新功能将在移动设备和Web上扩展功能,从而在设备之间创建一致的体验。 现在,以前只能在移动设备上访问的用户ID和共享之类的功能也将在台式机上可用。 这也为开发人员提供了一种在实现webview和chat扩展时进行测试和调试的简便方法。
有两种使用Messenger扩展获取用户ID的方法: getUserId()
和getContext()
。 文档指出getUserId()
在桌面上不可用,但未提及getContext()
。
Howevew,有一个错误报告指出getContext()
调用在桌面上尚不可用。
该文档没有提及获取用户ID的其他方法。 应该怎么做?
首先,如果您阅读原始问题,您将看到getContext()
实际上确实可以在桌面(web)上运行,但是仅当通过bot直接发送的链接打开webview时才可以。
原版的
我正在使用webview开发Facebook(信使)机器人。 现在,所有任务中最基本的就是获取userId。
这是我遇到的一个大问题。 经过彻底调查,下面我将介绍案例和结果。
情况1:我的应用程序向我发送了一个带有web_url按钮(打开webview)和一个共享按钮的通用模板。
一切正常。 我得到了用户名。
情况2:在case 1
,我从消息中单击“共享”,然后与自己和我的应用共享。
从任一消息线程(I到我自己,或I到应用程序) getContext()
调用返回错误2018166 Permission not valid to call the SDK API.
并且askPermission()
返回2018154 Messenger Extensions unexpected error.
情况3:我使用beginShareFlow()
从网络beginShareFlow()
单击共享,然后与自己和机器人共享。
与case 2
相同
案例4:这是踢球者。
从case 2
或Android的case 3
激活Webview可以正常工作,并为我提供了用户ID。
情况5:与以前与该应用进行过互动的朋友分享。
当那个朋友激活webview时,从桌面失败,从android运行。
案例6:与未与该机器人互动的朋友分享。
在桌面上不起作用(通过按钮或通过beginShareFlow()
共享),它可以工作!
因此,将所有内容写完后,模式为:
只是为了澄清。 我通过使用getContext
而不是通过getUserId
来获取用户ID,而文档中专门说这不适用于桌面。
有什么我可以做的吗? 我希望我的漫游器的Web视图可以在台式机和移动设备上使用。
我可以想到一种解决方法,但这远非理想
编辑2
根据要求,在Webview中共享的有效负载为:
{
"attachment":{
"type":"template",
"payload":{
"template_type":"generic",
"elements": [{
"title":"Testing webview",
"default_action":{
"type":"web_url",
"webview_height_ratio": "full",
"messenger_extensions": true,
"url":"https://plenty.life/webview"
},
"buttons":[{
"type":"web_url",
"webview_height_ratio": "full",
"messenger_extensions": true,
"url":"https://plenty.life/webview",
"title":"Test"
}]
}]
}
}
}
尝试这个...
<script>
window.extAsyncInit = function() {
// the Messenger Extensions JS SDK is done loading
console.log("using getUserId in",window.name)
MessengerExtensions.getUserID(function success(uids) {
// User ID was successfully obtained.
var psid = uids.psid;
console.log(psid);
document.getElementById("userId").innerText="your User Id Is "+psid;
}, function error(err, errorMessage) {
// Error handling code
console.log("some Error",err,errorMessage)
});
MessengerExtensions.getContext('<appID>',
function success(result){
console.log("success",result)
},
function error(result){
console.log("error",result)
}
);
};
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.