0

我制作了一个 Facebook 应用程序。现在我需要使用弹出的权限框获取用户信息。如果用户已经验证了应用程序,facebook 不应该打开对话框以获得许可,但如果用户第一次访问应用程序,那么它必须打开一个对话框。我在这里要做的是......并得到像......

无法调用未定义的方法“showPermissionDialog”

FB.getLoginStatus(function (response) {
               if (response.status === 'connected') {
                   alert("1");
                   // the user is logged in and has authenticated your
                   // app, and response.authResponse supplies
                   // the user's ID, a valid access token, a signed
                   // request, and the time the access token
                   // and signed request each expire
                   var uid = response.authResponse.userID;
                   //alert(uid);
                   var accessToken = response.authResponse.accessToken;
                   jQuery("#<%= accessToken.ClientID %>").val(accessToken);
                   // alert(accessToken);
                   fqlQuerynew();
               } else if (response.status === 'not_authorized') {

                   // the user is logged in to Facebook,
                   // but has not authenticated your app
                   alert('not_authorized');

                   OnRequestPermission();
               } else {
                   alert("3");
                   //alert('the user isnt logged in to Facebook');
               }
           });


       };

       function OnRequestPermission() {
           var myPermissions = "publish_stream, manage_pages"; // permissions your app needs
           FB.Connect.showPermissionDialog("email,offline_access", function (perms) {
               if (!perms) {
                   alert("hi");
                   // document.location.href = 'YouNeedToAuthorize.html';
               } else {
                   alert("buy");
                   document.location.href = 'homePage.html';
               }
           });
       }
4

2 回答 2

0

这是您的代码的修改版本,我没有对其进行测试并且它不完整,但应该让您知道该怎么做:

FB.getLoginStatus(function (response) {
    if (response.status === 'connected') {
        var uid = response.authResponse.userID;
        var accessToken = response.authResponse.accessToken;
        jQuery("#<%= accessToken.ClientID %>").val(accessToken);
        fqlQuerynew();
    } else if (response.status === 'not_authorized') {
        OnRequestPermission();
    } else {
        ...
    }
});

function OnRequestPermission() {
    var myPermissions = "publish_stream, manage_pages"; // permissions your app needs
    FB.login(function(response) {
        if (response.status === 'connected') {
            FB.api("me/permissions", checkPermissions);
        }
        else {
            ....
        }
    }, { scope: "email,offline_access" });
}

function checkPermissions(response) {
    if (response.data && response.data.legth == 1) {
        var perms = response.data[0];
        // iterate over perms and check if the user has all needed permissions
    }
}
于 2012-05-26T11:13:01.587 回答
0

如果您刚刚从代码中复制并粘贴了它,那么我认为您在 FB.getLoginStatus '};' 之后添加了一个额外的右括号。

删除后尝试您的代码。如果它不起作用,那么我们可以知道您何时要检查登录状态,例如在单击某些社交按钮后或在加载页面时。

于 2012-05-26T10:48:33.597 回答