Messenger Bot FB Oauth只是刷新webview

时间:2017-10-30 05:29:17

标签: javascript facebook-javascript-sdk facebook-messenger messenger facebook-messenger-bot

我的机器人用户使用Facebook进行身份验证以提供权限。这在桌面上的WebView中完美运行,但是当我尝试使用移动设备并点击"继续作为杰克"它表现得好像页面只是令人耳目一新,并没有启动oauth。我在Messenger WebView之外的移动设备上尝试了oauth,它运行正常。



<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>HomeSlanger | Login</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
  </head>
  <body>
    <div id="fb-root"></div>
    <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.net/en_US/sdk.js#xfbml=1&version=v2.10&appId=128153724471298';
        fjs.parentNode.insertBefore(js, fjs);
      }(document, 'script', 'facebook-jssdk'));
      (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'));
    </script>

    <div style="margin: 30vh auto 0px auto; text-align: center; padding-left: 8vw; padding-right: 8vw;">
      <p>Please login with Facebook to give HomeSlanger Bot permission to manage your pages and post for you</p>
      <div class="fb-login-button" data-max-rows="1" data-size="large" data-button-type="continue_with" data-show-faces="false" data-auto-logout-link="false" data-use-continue-as="true" data-scope="public_profile,email,manage_pages,pages_show_list,pages_messaging,pages_messaging_subscriptions,publish_actions" onlogin="login"></div>
    </div>

    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script>
      function login(resp) {
        MessengerExtensions.getContext('128153724471298', function(context) {
          axios.post('https://homeslanger-agent.ngrok.io/v1/oauth', {
            psid: context.psid,
            accessToken: resp.authResponse.accessToken,
            profileId: resp.authResponse.userID,
            signedRequest: resp.authResponse.signedRequest
          }).then(function(resp2) {
            var data = resp2.data;
            if(data.err) return alert(data.err);
            MessengerExtensions.requestCloseBrowser();
          }).catch(function(err) {
            alert('An error has occured, please try again or contact support if issues persist');
          });
        }, function(err) {
          alert('An error has occured, please try again or contact support if issues persist');
        });
      }
    </script>
  </body>
</html>
&#13;
&#13;
&#13;

0 个答案:

没有答案