【问题标题】:Is there a JavaScript API for sending notifications to Facebook users?是否有用于向 Facebook 用户发送通知的 JavaScript API?
【发布时间】:2018-05-26 05:40:05
【问题描述】:

我目前正在一个网站上开发 Facebook 应用程序,该应用程序需要在不使用用户界面对话框的情况下向应用程序的用户发送通知。在阅读了一些博客后,我得出结论,该选项仅在 PHP API 的示例中可用。我只能找到这个例子:

http://developers.facebook.com/docs/channels/

是否有 JavaScript API 可以做到这一点?

经过更多阅读,我发现 FB.api 可以处理图形对象 api 以及其他将被弃用的 api,并且我得到了以下工作:

FB.api('/1175241653/apprequests', 'post', 
       { message: "This is a Good Request!!" }, 
       function (response) {
           if (!response || response.error) {
              alert('Error occured , Request Failed :(( ');
           } else {
              alert('Request is sent successfully');
           }
        });

但是,如果登录用户的 id 不是该 id,则该 id 号 1175241653 不起作用。

因此,这需要与 Facebook 用于检索登录到应用程序的人的 ID 相同的功能。有没有办法做到这一点?

【问题讨论】:

    标签: javascript facebook api request


    【解决方案1】:

    现在,我以各种方式完成了这项工作,我想与可能处理的人分享它:))

    让我们说第一,从你的应用程序向你的应用程序中的任何 facebook 注册用户发出单个应用程序请求,如下所示:

    var data =
        {
            message: "Hey there, something good happened over here !",
            access_token: "AAADdf39DLxgBANEwZA9ZCfZCSbtdfcZBtstWMMsW5JiZBjVW2Ucx234sedhHSZCm8aEABzvhWPBNWi1bTKwZBq0EcgZD"
        }
    
    
    FB.api('/68751034/apprequests', 
           'post', 
           data, 
           function (response) {
               console.log(response);
               if (!response || response.error) {
    
               } else {
    
               }
           });
    

    应提供access_token 以验证应用程序对注册用户的请求。

    如果您不了解访问令牌,可以在 facebook 网站上阅读:

    http://developers.facebook.com/docs/authentication/

    此外,如果您想在一个请求调用中向一组用户发送批量请求,Facebook 网站上也有一个支持页面:

    http://developers.facebook.com/docs/reference/api/batch/

    这是我的意思的一个示例:

    var _batch = [];
    
    for (var i = 0; i < _socialids.length; i++) {
       _batch.push({ 
           method: 'post', 
           relative_url: _socialids[i] + '/apprequests/?access_token=' + _accessTokens[i], 
           body: "message= This is a request sent to many users" });
        }
       if (_batch.length > 0) {
           FB.api('/', 'POST', { batch: _batch }, function (res) {
               // Do whatever when the batch request is sent
           });
       }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多