javascript - 将 Facebook 好友添加到网站 [Graph API 2.5]

标签 javascript facebook facebook-graph-api facebook-javascript-sdk facebook-invite

我正在开发一个网站,用户可以在其中添加他们的 Facebook 好友。通常我会使用 apprequests,但此功能仅适用于 2.3 版及以上版本的游戏。目前我只能使用 send request Graph API 的功能可以向 friend 发送消息,但我还想检索向其发送消息的 friend 列表。

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 函数在控制台中单独打印整个 friend 列表,但现在这就是我能够打印的全部内容..

   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 的游戏,则发送对话框(或移动设备上的消息对话框)是邀请 friend 的唯一选项。

如果您想在用户的好友加入/授权该应用时向该用户发送通知,只需使用 user_friends 进行授权,然后向返回列表中的所有好友发送通知即可。毕竟,您只会获得那些已经授权您的应用程序的 friend 。您不需要为此存储受邀请的 friend 。

关于javascript - 将 Facebook 好友添加到网站 [Graph API 2.5],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35288453/

相关文章:

javascript - 如何用另一个字母/特殊字符替换字符串中的所有字母?

android - 在没有授权 token 的情况下获取 Facebook 页面的公开帖子

ios - Facebook 好友邀请的 Swift 2.0 代码

java - 如何使用 Facebook SDK android 获取 Facebook 照片、全名、性别

ios - 从 iPhone 应用程序发布到 Facebook 墙的链接

javascript - Next.js 在 html 标记中渲染应用程序作为字符串

javascript - 从数组中选择特定元素

javascript - 如果我有 Javascript/CXF,我还需要 (Spring) MVC 吗?

HTML 5 添加 XML 命名空间

android - 通过 Facebook、电子邮件和短信/彩信共享音频文件 (.mp3)