检查Facebook上的用户权限

时间:2015-01-02 18:37:23

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

我尝试检查用户是否已接受权限列表。我有这个:

           window.FB.api("me/permissions", function (resp) {
                var IsValid = true;
                var perm = "public_profile";
                var PermsArray = resp.data;
                var PermsNeeded = perm.split(",");

                var Unit = PermsNeeded.length;

                for (var I = 0; I < Unit; I++) {
                    var Per = PermsNeeded[I];

                    if (PermsArray[Per] == null) {
                        IsValid = false;
                        break;
                    }
                }

                callBack(IsValid);
            });

当我尝试这个时,在我接受了public_profile权限后,我得到IsValid = false。

什么错了? :■

更新 这有效:

window.FB.api("me/permissions", function (resp) {
                var IsValid = false;
                var perm = "public_profile";
                var PermsArray = resp.data;
                var PermsNeeded = perm.split(",");

                var Unit = PermsNeeded.length;
                var UnitAccepted = PermsArray.length;

                for (var I = 0; I < Unit; I++) {
                    var Per = PermsNeeded[I];

                    for (var J = 0; J < UnitAccepted; J++) {
                        var AccPer = PermsArray[J];

                        if (AccPer.permission == Per) {
                            IsValid = true;
                            break;
                        } else {
                            IsValid = false;
                        }
                    }
                }

                callBack(IsValid);
            });

0 个答案:

没有答案