【问题标题】:App authentication dialog box for facebook appfacebook 应用程序的应用程序身份验证对话框
【发布时间】:2012-05-26 09:18:21
【问题描述】:

我制作了一个 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';
               }
           });
       }

【问题讨论】:

    标签: asp.net facebook facebook-graph-api


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

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

      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-11-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-08-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多