如何使用 Javascript SDK 删除应用程序请求

发布于 2024-12-11 04:29:35 字数 736 浏览 1 评论 0原文

我有以下 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 。

I've got the following Javascript code:

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

This seems to be the standard approach I see people using. Unfortunately, I get an error.
The response object I get from this states the following:
"App Request Recipient Must Be Specified: The recipient for this app request must be specified through a user-signed access token or the fully specified app request ID."

So, I try using requestid_facebookid instead... no luck. I try passing in my access token via

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

Both give me the same error.

Any tips would be greatly appreciated.

Edit: Just for clarity's sake, the authToken I am getting is from response.authResponse.accessToken from getLoginStatus.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

泛滥成性 2024-12-18 04:29:35

我仍然不确定如何删除这些请求。不过,我确实想出了一个使用图形 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 和 Facebook 网页删除这些请求。如果有人有任何想法,我仍然想知道如何删除用户应用程序请求。

I'm still not sure how to delete these requests. However, I did come up with a workaround with the graph api.

New code is as follows:

Sending the app request

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 );
        }
    });

And deleting it

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

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

This seemed to change the type of the request from a user app request to an app request. The logo changed from my profile picture to the app icon. I was able to delete these requests both from the graph api and through facebooks webpage. I'd still love to know how to delete the user app requests if anyone has any ideas.

梦开始←不甜 2024-12-18 04:29:35

我在网上搜索了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 种可能的回调方式:

选项 1 使用 Facebook.api

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');
    }
} 

I lost 6 hours searching online, at the end I figured it out by myself.

send request:

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 possible way for the callback:

Option 1 with Facebook.api

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")

        }
}

option 2: with 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);
        }
    }
}

callback function for the delete:

private function onRequestDelete(result:Object, fail:Object):void{
    if(result == null){
        trace('Delete Request faild');
    }else{
        trace('Delete Request succes');
    }
} 
蓝眼睛不忧郁 2024-12-18 04:29:35

如果您想使用 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);
                        });
                    }
                });
            } 
        });

If you want to remove all the Facebook pending app requests of the current logged user with the Javascript SDK you can do the following:

        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);
                        });
                    }
                });
            } 
        });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文