共享时,Facebook Webview失败 [英] Facebook webview fails when shared

查看:112
本文介绍了共享时,Facebook Webview失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最终编辑 这是一个错误.提交报告后,该地址已得到解决.

FINAL EDIT This was a bug. After filing the report it was addressed.

编辑

我正在尝试在我的facebook Messenger机器人的网络视图中获取用户ID.它在移动设备上可以正常运行,但在台式机(网络)上无法运行.情况并非如此.

I am trying to get user id in a webview of my facebook messenger bot. It works fine on mobile, yet fails on desktop (web). This should not be the case.

Messenger 2.1发布声明给出以下报价:

扩展SDK的桌面支持:这项新功能将在移动设备和Web上扩展功能,从而在设备之间创建一致的体验.现在,用户ID 之类的功能以及以前只能在移动设备上访问的共享功能也将在台式机上可用.这也为开发人员提供了一种在实现Webview和聊天扩展时进行测试和调试的简便方法.

Desktop support for Extensions SDK: This new feature will extend functionality across mobile and web, creating a consistent experience across devices. Now, features like user ID and sharing that used to only be accessible on mobile will be available on desktop as well. This also provides developers with an easier way to test and debug when implementing webview and chat extensions.

有两种使用Messenger扩展名获取用户ID的方法:getUserId()getContext().文档指出getUserId()在台式机上不可用,但没有提及getContext().

There are two ways to get the user id with messenger extensions: getUserId() and getContext(). The docs state that getUserId() is not available on desktop, but make no mention of getContext().

Howevew,有一个错误报告指出getContext()调用不是还可以在台式机上使用.

Howevew, there is a bug report that states that getContext() call is not yet available on desktop.

文档没有提及获取用户ID的其他方法.应该怎么做?

The docs mention no other ways of getting user id. How is one supposed to do that?

作为一个提示,如果您阅读原始问题,您会看到getContext()实际上确实可以在台式机(网络)上运行,但前提是必须通过漫游器直接发送的链接打开网络视图.

As a kicker, if you read the original question, you will see that getContext() actually does work on desktop (web), but only if the webview is opened through a link sent directly by the bot.

原始

我正在使用webview开发Facebook(信使)机器人. 现在,所有任务中最基本的就是获取userId.

I am working on a Facebook (messenger) bot using webview. Now the most basic of all tasks is to get the userId.

这是我遇到的一个大问题.经过彻底调查,下面我将介绍案例和结果.

This is where I hit a big problem. Having investigated it thoroughly, below I present cases and results.

  • 情况1:我的应用程序向我发送了一个通用模板,该模板带有一个web_url按钮(用于打开webview)和一个共享按钮.

  • case 1: my app sends me a generic template with a web_url button (that opens the webview) and a share button.

一切正常.我得到了用户ID.

Everything works great. I get the user id.

情况2:我单击case 1中消息中的共享",然后与自己和我的应用共享.

case 2: I click share from the message in case 1, and share it with myself and my app.

从任一消息线程(我到我自己,或我到应用程序)getContext()调用返回错误2018166 Permission not valid to call the SDK API.,而askPermission()返回2018154 Messenger Extensions unexpected error.

from either message thread (I to myself, or the I to app) getContext() call return error 2018166 Permission not valid to call the SDK API. and askPermission() returns 2018154 Messenger Extensions unexpected error.

案例3:我使用beginShareFlow()在网络视图中单击共享,然后与自己和机器人共享.

case 3: I click share from inside the webview using beginShareFlow() and share with myself and the bot.

case 2

案例4:这是踢手.

从Android的case 2case 3激活Web视图,可以正常工作并为我提供用户ID.

activating the webview from case 2 or case 3 from Android, works and gives me the user id.

案例5:与以前与该应用进行过互动的朋友分享.

case 5: sharing to a friend who has interacted with the app before.

当那个朋友激活webview时,它在桌面上失败了,而在android系统中.

When that friend activates the webview, from desktop it fails, from android works.

案例6:与与机器人互动的朋友共享.

case 6: sharing to a friend who has not interacted with the bot.

不起作用(通过按钮或通过beginShareFlow()共享)!

on desktop doesn't work (sharing by button or through beginShareFlow()), it works!

因此,将所有内容写完后,模式是:

So, after writing all of this out, the pattern is:

  • 在android上,webview共享按预期方式工作:无论用户是否与bot交互,我都可以获取用户ID.
  • 在桌面上,WebView唯一提供用户ID的时间是机器人发送带有WebView链接的消息的时间.用户共享后,Web视图仍会打开,但不提供上下文.

仅作澄清.我通过使用getContext而不是通过getUserId来获得用户ID,而文档专门指出该ID在台式机上不起作用.

Just to clarify. I get the user id by using getContext, and not by getUserId which the docs specifically say doesn't work on desktop.

有什么我可以做的吗?我希望我的漫游器的Web视图可以在台式机和移动设备上使用.

Is there anything I can do about this? I would like my bot's webviews to work both on desktop and mobile.

我可以想到一种解决方法,但这远非理想

编辑2

根据要求,在Webview中共享的有效负载为:

As requested, the payload for sharing within webview is:

{
  "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>

这篇关于共享时,Facebook Webview失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆