【问题标题】:Facebook Send Request returns ErrorFacebook 发送请求返回错误
【发布时间】:2023-03-20 01:02:02
【问题描述】:

我正在尝试以这种方式与预先指定的收件人弹出对话框:

FB.init({
  appId      : 'MYAPPID',
  status     : true,
  cookie     : true, 
  xfbml      : true,  
  frictionlessRequests: true
}); 

function sendRequestToRecipients() 
{
    FB.ui({method: 'apprequests',
      message: 'You have just received a PP request.',
      to: '100000526845569'
    }, requestCallback);
}

sendRequestToRecipineds();

当弹出窗口打开时出现错误:An error occurred. Please try later

当我查看弹出窗口的请求 URL 时,我看到以下内容:

https://www.facebook.com/dialog/apprequests?message=You%20have%20just%20received%20a%20PP%20request.&to=100000526845569&api_key=&app_id=&locale=en_US&sdk=joey&display=popup&frictionless=false&next=http%3A%2F%2Fstatic.ak.facebook.com%2Fconnect%2Fxd_arbiter.php%3Fversion%3D18%23cb%3Df23f09878cdaf1e%26origin%3Dhttp%253A%252F%252Fmyhost.com%252Ff1868d80900b7a%26domain%3Dmyhost.com%26relation%3Dopener%26frame%3Df27cb35acbd146c%26result%3D%2522xxRESULTTOKENxx%2522

我认为有些信息尚未发送: api_key, app_id

怎么会?有什么想法吗?

使用 facebook 登录可以完美运行。多人选择器也是如此。


<script>
window.fbAsyncInit = function() {
 // init the FB JS SDK
FB.init({
  appId      : 'MYAPPID', // App ID from the App Dashboard
  channelUrl : '//mydomain.com/channel.html', // Channel File for x-domain communication
  status     : true, // check the login status upon init?
  cookie     : true, // set sessions cookies to allow your server to access the session?
  xfbml      : true,  // parse XFBML tags on this page?
  frictionlessRequests: true
});


};

 // Load the SDK's source Asynchronously

 (function(d, debug){
   var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
   if (d.getElementById(id)) {return;}
   js = d.createElement('script'); js.id = id; js.async = true;
   js.src = "//connect.facebook.net/en_US/all" + (debug ? "/debug" : "") + ".js";
   ref.parentNode.insertBefore(js, ref);
 }(document, /*debug*/ false));

function sendRequestToRecipients() {

    FB.ui({method: 'apprequests',
      message: 'You have just received a PP request.',
      to: '100000143396036'
    }, requestCallback);
  }

  function sendRequestViaMultiFriendSelector() {
    FB.ui({method: 'apprequests',
      message: 'My Great Request'
    }, requestCallback);
  }

  function requestCallback(response) {
    // Handle callback here
  }

 </script>

这就是它的制作方式

【问题讨论】:

    标签: javascript php facebook facebook-graph-api facebook-javascript-sdk


    【解决方案1】:

    尝试在调用FB.init()(如果没有的话)之前异步加载javascript SDK,如下所示:

    <script>
    
      window.fbAsyncInit = function() 
      {
        FB.init({
          appId      : APP_ID,
          status     : true, 
          cookie     : true, 
          xfbml      : true,  
          frictionlessRequests: true
        });
        //Additional Code here
      };        
    
     // Load the SDK Asynchronously
     (function(d){
       var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
       if (d.getElementById(id)) {return;}
       js = d.createElement('script'); js.id = id; js.async = true;
       js.src = "//connect.facebook.net/en_US/all.js";
       ref.parentNode.insertBefore(js, ref);
       }
     (document));
    
    </script>
    

    【讨论】:

    • 是的,恐怕这正是它在我的脚本中完成的方式..问题隐藏在其他地方.. :(
    • 我认为上面的脚本你在加载 SDK js 之前调用了FB.init 函数。
    【解决方案2】:

    已修复。

    奇怪,但是 ASYNC SDK 的存在把这一切搞砸了。

    谢谢

    【讨论】:

      猜你喜欢
      • 2021-04-24
      • 1970-01-01
      • 2011-10-11
      • 1970-01-01
      • 1970-01-01
      • 2021-01-14
      • 2021-01-17
      • 2012-12-31
      • 2022-12-19
      相关资源
      最近更新 更多