实现Facebook Login for Business时使用User Access Token遇Minified invariant #21945错误
Facebook Login for Business 非应用角色账号登录失败问题
背景与配置
我正在实现Facebook Login for Business,目标是让企业客户生成User Access Token。按照官方指引在Facebook应用中完成配置后,使用带config_id的登录按钮组件:
<fb:login-button config_id="<CONFIG_ID>" onlogin="checkLoginState();"> </fb:login-button>
我基于官方Web登录流程的示例代码修改,将原示例中带scope的登录按钮替换为上述带config_id的版本。
我有两个测试Facebook账号:
- 账号1:持有该应用的开发者角色
- 账号2:在该应用中无任何角色
业务需求是让账号2这类无应用角色的客户账号能正常登录,因为我们不需要客户拥有应用权限,仅需代表他们投放广告。
问题现象
账号1登录时可正常生成访问令牌,但账号2登录时会触发错误提示,点击错误中的链接会跳转到Facebook内部登录页面。
我已尝试以下方案但均未解决问题:
- 使用非压缩版本的Facebook JS SDK
- 将SDK加载地址中的
sdk替换为all(参考网络搜索到的解决方案)
完整代码
<!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>
补充说明:该应用已通过访问验证和应用审核。
内容的提问来源于stack exchange,提问作者Nawaz Hussain
相关产品推荐
相关产品推荐

