本文介绍了Facebook Messenger扩展错误:2071010的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用部署在heroku上的nodejs开发用于Messenger平台的聊天机器人.我正在尝试在网络视图中获取用户ID.我已将Messenger扩展程序字段设置为true,使用最新更新的android应用程序将我的域列入白名单,并且从现在开始,webview支持Web浏览器,我也在safari浏览器中查看它.

I am developing a chatbot for messenger platform using nodejs deployed on heroku.I am trying to get the user id in the webview.I have set the messenger extension field to true, whitelisted my domain, using latest updated version android app and also since now webview support the web browser, I am also viewing it in safari browser.

Messenger SDK已完美加载.我检查是否支持浏览器,结果是-> true.我仍然在获取用户ID时遇到问题.我的代码是:

The messenger sdk is loading perfectly. I the check whether browser is supported or not which I get as result->true.Still I am facing problem getting the user id.My code is:

<script>
        (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 = "https://connect.facebook.com/en_US/messenger.Extensions.js";
          fjs.parentNode.insertBefore(js, fjs);
        }(document, 'script', 'Messenger'));

        window.extAsyncInit = function () {
            var isSupported = MessengerExtensions.isInExtension();
            alert(isSupported);
            // the Messenger Extensions JS SDK is done loading
            MessengerExtensions.getUserID(function success(uids) {
                var psid = uids.psid;
                alert(psid);
            }, function error(err) {
                alert("Messenger Extension Error: " + err);
            });
        };
    </script>

注意:我已经搜索了此问题的解决方案,但没有一个起作用,因此我发布了此错误.

NOTE: I have searched the solution for this problem but none of them work, hence I am post this error.

推荐答案

好,我再次阅读了文档.该文档说,桌面版Webview可以运行,但目前不支持诸如getUserIds()之类的警告.

Well, I read the documentation once again.The documentation say that the webview for desktop works but presently doesn't support some caveats like getUserIds().

我发现了两个替代解决方案来解决获取"psid"的问题,第一个很简单,您可能已经知道了它,因为许多聊天机器人(如"2k17 Resolutions")都在使用它.

I found two alternate solution to over come the problem of getting the "psid", the first one is simple and you might be knowing about it as many chatbots like "2k17 Resolutions" are using it.

1.将nodejs应用程序中的"senderid"作为参数添加到Webview的url,然后在页面本身上获取它. "senderid"和"psid"相同.

1.Adding the "senderid" in your nodejs app as parameter to the url of your webview and then fetching it on the page itself. The "senderid" and "psid" are same.

  1. 通过从Messenger ssdk调用getContext()获得psid. getContext()返回json中的4个字段对象,分别是"thread_type","tid","psid","signed_request",其中psid是我正在寻找的对象.下面是完整的工作代码.

  1. Getting the psid from the getContext() by calling it from messenger js sdk. The getContext() return 4 field in jsonobject, which are "thread_type","tid","psid","signed_request" where psid is what I was looking for.Below is the complete working code.

<script>
    (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 = "https://connect.facebook.com/en_US/messenger.Extensions.js";
      fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'Messenger'));
    window.extAsyncInit = function () {
        var isSupported = MessengerExtensions.isInExtension();
        alert(isSupported);
        // the Messenger Extensions JS SDK is done loading
        MessengerExtensions.getContext('YOU_APP_ID',
          function success(result){
            alert("Success: "+result.psid);
          },
          function error(result){
            alert(JSON.stringify(result));
          }
        );
    };
</script>

这是线程上下文文档的链接: https://developers .facebook.com/docs/messenger-platform/webview/context

And here is the link for Thread context documentation: https://developers.facebook.com/docs/messenger-platform/webview/context

两天前,Messenger进行了几次新更新,其中一项更新使Web视图与所有浏览器兼容,因此getContext()现在可与任何浏览器一起使用.

Two days back the messenger got few new updates out of which, one of the new update make the web view compatible with all browser and hence now getContext() is working with any browser.

这篇关于Facebook Messenger扩展错误:2071010的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 19:02