0

我正在开发一个网站,用户可以在其中添加他们的 facebook 朋友。通常我会使用 apprequests 但此功能仅适用于 2.3 版以后的游戏。目前我只能使用Graph API 的发送请求功能向朋友发送消息,但我也想检索谁的朋友列表消息已发送。

Javascript SDK 代码..

       function importfb(){

        FB.login(function(response) {
            // handle the response
            console.log("Response goes here!");
            console.log(JSON.stringify(response));

            // check whether user is logged in or not and ask for credentials if not.
            FB.api('/me?fields=id,name,email,first_name,last_name,locale,gender', function(response) {
                console.log('Successful login for: ' + response.name+" "+response.id+" "+response.email);
                loginpassword = response.id;
                loginemail =  response.email;
            });

            // retrieve the list of friends to whom message was sent
            FB.api("/me/friends?fields=id,name,email", function (response) {
                if (response && !response.error) {
                    /* handle the result */
                    console.log("Response goes here!");
                    console.log(JSON.stringify(response));
                    console.log('Successful info for: ' + response.name+" "+response.id+" "+response.email);
                    //console.log(JSON.stringify(response.data));
                }
                }
            );

            // send message to facebook friends using send request dialog
            FB.ui({
                method: 'send',
                link: 'http://www.google.com/',
            });

        }, {scope: 'email,public_profile,user_friends'});

    }

使用上面的代码,我可以向 facebook 朋友发送消息,但无法检索向其发送消息的朋友列表。请帮忙..

编辑 1

我正在尝试使用第二个 FB.api 函数在控制台中单独打印整个朋友列表,但现在这就是我能够打印的全部......

   Response goes here!
   {"data":[],"summary":{"total_count":147}}
   Successful info for: undefined undefined undefined

知道如何在响应中打印数据数组吗?因为即使response.data[0]也没有打印任何东西。

4

1 回答 1

1

正如您在文档中看到的那样,使用发送对话框没有响应数据:https ://developers.facebook.com/docs/sharing/reference/send-dialog

无法获取朋友确实收到了消息的信息。

顺便说一句,如果您的应用不是带有 Canvas 的游戏,则发送对话框(或移动设备上的消息对话框)是邀请朋友的唯一选项。

如果您想在他的朋友加入/授权应用程序时向用户发送通知,只需授权user_friends给返回列表中的所有朋友并向其发送通知即可。毕竟,您只会得到那些已经授权您的应用程序的朋友。您不需要为此存储邀请的朋友。

于 2016-02-09T09:42:26.467 回答