获取“缩小不变式#21945;”使用用户访问令牌实现“Facebook Login for Business”时出错

问题描述 投票:0回答:1

我正在尝试实现Facebook 企业登录,根据我的要求,我需要请求客户业务用户生成用户访问令牌

根据文档,我在 Facebook 应用程序上创建了一个配置,并且应该从 sdk 中调用它:

<fb:login-button config_id="<CONFIG_ID>" onlogin="checkLoginState();">
</fb:login-button>

我还使用了here中的代码,它为登录流程提供了完整的 HTML/JS 代码。在示例中,我替换了:

<fb:login-button scope="public_profile,email" onlogin="checkLoginState();">
</fb:login-button>

致:

<fb:login-button config_id="<CONFIG_ID>" onlogin="checkLoginState();">
</fb:login-button>

我有两个 Facebook 帐户并且

  1. 在 Facebook 应用程序上担任开发人员角色
  2. 在应用程序上根本没有任何作用

我需要 2 个人才能登录,因为我们不希望我们的客户在应用程序上拥有角色,并且希望代表他们部署广告。

如果我使用帐户 1 登录 Facebook,我就能够生成访问令牌。如果我已经使用帐户 2 登录,或者我尝试登录,则会收到以下错误消息:

Error Message

错误消息中的链接引导我进入内部 FB 登录页面:

Internal FB Login

我已经尝试使用here提到的非缩小版本,甚至将源中的“sdk”替换为“all”,这在谷歌搜索期间其他Facebook查询的其他答案中提到,但无法使其工作,并且仍然出现错误。

我的完整代码可以在下面找到:

<!DOCTYPE html>
<html>
<head>
<title>Facebook Login JavaScript Example</title>
<meta charset="UTF-8">
</head>
<body>
<script>

  function statusChangeCallback(response) {  // Called with the results from FB.getLoginStatus().
    console.log('statusChangeCallback');
    console.log(JSON.stringify(response));                  // The current login status of the person.
    console.log(response.status);
    if (response.status === 'connected') {   // Logged into your webpage and Facebook.
      testAPI();  
    } else {                                 // Not logged into your webpage or we are unable to tell.
      document.getElementById('status').innerHTML = 'Please log ' +
        'into this webpage.';
    }
  }


  function checkLoginState() {               // Called when a person is finished with the Login Button.
    FB.getLoginStatus(function(response) {   // See the onlogin handler
      statusChangeCallback(response);
    });
  }


  window.fbAsyncInit = function() {
    FB.init({
      appId      : <APP_ID>,
      cookie     : true,                     // Enable cookies to allow the server to access the session.
      xfbml      : true,                     // Parse social plugins on this webpage.
      version    : 'v18.0'           // Use this Graph API version for this call.
    });


    FB.getLoginStatus(function(response) {   // Called after the JS SDK has been initialized.
      statusChangeCallback(response);        // Returns the login status.
    });
  };
 
  function testAPI() {                      // Testing Graph API after login.  See statusChangeCallback() for when this call is made.
    console.log('Welcome!  Fetching your information.... ');
    FB.api('/me', function(response) {
      console.log('Successful login for: ' + response.name);
      document.getElementById('status').innerHTML =
        'Thanks for logging in, ' + response.name + '!';
    });
  }

</script>


<!-- The JS SDK Login Button -->

<fb:login-button config_id="<CONFIG_ID>" onlogin="checkLoginState();">
</fb:login-button>

<div id="status">
</div>

<!-- Load the JS SDK asynchronously -->
<script async defer crossorigin="anonymous" src="https://connect.facebook.net/en_US/sdk/debug.js"></script>
</body>
</html>

如有任何帮助,我们将不胜感激,谢谢。

编辑:我的应用程序已通过访问验证和应用程序审核。

facebook facebook-graph-api facebook-javascript-sdk facebook-login
1个回答
0
投票

我希望这可以帮助引导您走向正确的方向。

我也遇到了同样的问题,但我删除了 public_profile,email 范围并尝试使用pages_read_engagement,这似乎解决了黑屏问题。

不确定这意味着什么,但这意味着范围可能有问题。

© www.soinside.com 2019 - 2024. All rights reserved.