javascript-在js api中获取facebook朋友列表

I am getting user info but unable to get friend list.    

<script>
    function sortMethod(a, b) {
        var x = a.name.toLowerCase();
        var y = b.name.toLowerCase();
        return ((x < y) ? -1 : ((x > y) ? 1 : 0));
    }

    window.fbAsyncInit = function() {
        FB.init({ appId: 'xxxxxxxxx', 
            status: true, 
            cookie: true,
            xfbml: true,
            oauth: true
        });

        function updateButton(response) {
            var button = document.getElementById('fb-auth');

            if (response.authResponse) { // in case if we are logged in
                var userInfo = document.getElementById('user-info');
                FB.api('/me', function(response) {
                    userInfo.innerHTML = '<img src="https://graph.facebook.com/' + response.id + '/picture">' + response.name;
                    button.innerHTML = 'Logout';
                });

                // get friends
                FB.api('/me/invitable_friends', function(response) {
                    var result_holder = document.getElementById('result_friends');
                    var friend_data = response.data.sort(sortMethod);

                    var results = '';
                    for (var i = 0; i < friend_data.length; i++) {
                        results += '<div><img src="https://graph.facebook.com/' + friend_data[i].id + '/picture">' + friend_data[i].name + '</div>';
                    }

                    // and display them at our holder element
                    result_holder.innerHTML = '<h2>Result list of your friends:</h2>' + results;
                });

                button.onclick = function() {
                    FB.logout(function(response) {
                        window.location.reload();
                    });
                };
            } else { // otherwise - dispay login button
                button.onclick = function() {
                    FB.login(function(response) {
                        if (response.authResponse) {
                            window.location.reload();
                        }
                    }, {scope:'email'});
                }
            }
        }

        // run once with current status and whenever the status changes
        FB.getLoginStatus(updateButton);
        FB.Event.subscribe('auth.statusChange', updateButton);    
    };

    (function() {
        var e = document.createElement('script'); e.async = true;
        e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
        document.getElementById('fb-root').appendChild(e);
    }());
    </script>

用户登录但
无法显示Facebook好友列表.

代码在新的SDK之前可以正常工作.
在我/朋友之前使用invitable_friends.

任何人请帮忙.

还有除此之外呢?

解决方法:

您需要在授权过程中要求user_friends:

FB.login(function(response) {
    if (response.authResponse) {
        window.location.reload();
    }
}, {scope:'email,user_friends'});

您既需要/ me / friends也需要/ me / invitable_friends,请参阅Facebook文档:https://developers.facebook.com/docs/games/invitable-friends/v2.1

尽管您只会与/ me / friends一起使用该应用程序的朋友.有关更多信息,请参见changelog:https://developers.facebook.com/docs/apps/changelog

CBroe在您的问题中评论的内容也非常重要. invitable_friends仅适用于facebook.com上的游戏.

上一篇:微信公众号和小程序支付功能 获取支付参数 JSAPI


下一篇:asp.net mvc内微信pc端、H5、JsApi支付方式总结