将 Facebook 好友添加到网站 [图形 API 2.5]

Add Facebook friends to Website [Graph API 2.5]

本文关键字:API 图形 网站 Facebook 好友 添加      更新时间:2023-09-26

我正在开发一个网站,用户可以在其中添加他们的Facebook朋友。通常我会使用 apprequests,但此功能仅适用于 2.3 版以上的游戏。目前,我只能使用图形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] 也不会打印任何东西。

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

没有办法获得哪些朋友确实收到了消息的信息。

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

如果您想在好友加入/授权应用时向用户发送通知,只需使用 user_friends 授权并向返回列表中的所有好友发送通知即可。毕竟,您只能获得那些已经授权您的应用程序的朋友。您无需为此存储受邀的朋友。