English 中文(简体)
Ffacebook 应用程序的 App 认证对话框
原标题:App authentication dialog box for facebook app

我制作了一个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 ;
               }
           });
       }
问题回答

如果您只是复制并粘贴了您的代码, 那么我想您在 FB. Get Loginstatus } 之后添加了一个额外的闭锁括号 ; 。

删除此选项后, 请尝试您的代码。 如果它不工作, 那么我们可以知道什么时候您要检查登录状态, 就像点击某个社会按钮或加载页面之后一样 。

此处是您的代码的修改版本, 我测试过它, 它不完整, 但应该给你们一个想法, 告诉你该怎么做 :

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
    }
}




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签