1

我有以下 Javascript 代码:

        function RemoveRequest( requestToRemove )
        {           
            FB.api( requestToRemove, 'delete', function(response) {
                console.log(response);
              });
        }

这似乎是我看到人们使用的标准方法。不幸的是,我得到一个错误。我从中得到的响应对象声明如下:“必须指定应用程序请求收件人:必须通过用户签名的访问令牌或完全指定的应用程序请求 ID 指定此应用程序请求的收件人。”

所以,我尝试使用 requestid_facebookid 代替......没有运气。我尝试通过

FB.api(requestToRemove, 'delete', {access_token:accessToken}, function(response) {
                console.log(response);
              });

两者都给了我同样的错误。

任何提示将非常感谢。

编辑:为了清楚起见,我得到的 authToken 来自 getLoginStatus 的 response.authResponse.accessToken。

4

3 回答 3

4

我仍然不确定如何删除这些请求。但是,我确实想出了一个使用图形 api 的解决方法。

新代码如下:

发送应用请求

var params = {};
params['message'] = 'My message!';
params['title'] = 'My title!';
params['to'] = inID;
params['access_token'] = accessToken;
FB.api('/me/apprequests', 'POST', params, 
    function(response){
        if( response )
        {
            console.log( response );
        }
    });

并删除它

function RemoveRequest( requestToRemoveID, facebookUserID )
{
        requestToRemoveID = '/'+requestToRemoveID + '_' + facebookUserID;
    console.log( requestToRemoveID );

    FB.api( requestToRemoveID, 'DELETE', function(response) {
        console.log(response);
        });
}

这似乎将请求的类型从用户应用请求更改为应用请求。徽标从我的个人资料图片更改为应用程序图标。我能够从图形 api 和 facebooks 网页中删除这些请求。如果有人有任何想法,我仍然很想知道如何删除用户应用程序请求。

于 2011-10-23T18:44:12.147 回答
2

我在网上搜索了 6 个小时,最后我自己弄明白了。

发送请求:

private function invite():void
{
    var dat:Object = new Object();
    dat.message = "MyMessage";
    dat.title   = "MyTitle;
    dat.filters = ['app_non_users'];

    Facebook.ui('apprequests', dat, onUICallback);
}

2种可能的回调方式:

使用 Facebook.api 的选项 1

private function onUICallback(result:Object):void{  

    if(result == null){
        trace('User closed the pop up window without inviting any friends');
    }else{

        if(result.hasOwnProperty("request")){

            var data:Object = new Object();
            data.method = 'delete';
            var userid:String = "here goes the uid of the user that sent the request"
            var fullrequestID:String = result.request + '_' + userid;

            Facebook.api(fullrequestID, onRequestDelete, data, "POST")

        }
}

选项 2:使用 Facebook.deleteObject

private function onUICallback(result:Object):void{
    if(result == null){
        trace('User closed the pop up window without inviting any friends');
    }else{
        if(result.hasOwnProperty("request")){
            var userid:String = "here goes the uid of the user that sent the request"
            var fullrequestID:String = result.request + '_' + userid;           

            Facebook.deleteObject(fullrequestID, onRequestDelete);
        }
    }
}

删除回调函数:

private function onRequestDelete(result:Object, fail:Object):void{
    if(result == null){
        trace('Delete Request faild');
    }else{
        trace('Delete Request succes');
    }
} 
于 2012-02-08T14:29:21.640 回答
1

如果您想使用 Javascript SDK 删除当前登录用户的所有 Facebook 待处理应用程序请求,您可以执行以下操作:

        FB.getLoginStatus(function(response) {
            console.log(response);
            if (response.status === 'connected') {

                var uid = response.authResponse.userID;
                var accessToken = response.authResponse.accessToken;

                FB.api('/me/apprequests', function(response){
                    console.log( response );

                    for (var i = 0; i < response.data.length; i++){

                        FB.api(response.data[i].id, 'delete', function(response) {
                            console.log(response);
                        });
                    }
                });
            } 
        });
于 2015-05-28T18:33:14.443 回答