2011-05-05 116 views
0

我正在致力于一个Facebook应用程序,我们只需要在一个textarea中提供一条消息。现在我们直接在用户喜欢页面后请求扩展权限(应用程序隐藏,直到用户喜欢页面)。我们希望它可以在提交表单时使用。Facebook Jquery ajax权限请求?

有没有一种方法来加载弹出式样div(不是新窗口... jquery.load?)中的权限对话框,并使用脚本页作为我的回调uri并发布我的数据而不重新加载选项卡?如果使用正常形式,我已经这样做了,但是我们需要从FB中获取名称/图片/电子邮件/ bday以放入数据库。

任何帮助,即使是在正确的方向微调将非常感激!

/** ** UPDATED/

想和我想出了,它使用目前所有的软件开发工具包更新。我试图尽可能使其成为template-y,以便其他人可以使用它。

$("#submit").live('click',function() { 
    if (someErrors === true) { 
     // handle errors 
    } else { 
     FB.login(function(response) { 
      if (response.session) { 
       if (response.perms) { 
        FB.api('/me', function(response) { 
         // vars: response.session.uid, response.name, response.email, response.birthday, etc 
         // serialize data here for post 
         $.post("process.php",formData,function(data) { 
          if (data.error) { 
           // send json encoded error messages back to retrieve here like below: 
           // PHP: echo json_encode(array("error"=>"fail")); 
          } else { 
           /** 
           send data back json encoded: 
           PHP: echo json_encode(array("yourData"=>"{$yourData}","fb_id"=>"{$fb_id}","name"=>"{$name}")); 
           Now we have data like: 
           var profile = 'http://www.facebook.com/profile.php?id='+data.fb_id; 
           var image = '<img src="http://graph.facebook.com/'+data.fb_id+'/picture" />'; 
           var yourData = data.yourData; 
           **/ 
          } 
         }, "json"); 
        }); 
       } else { 
        // more errors 
       } 
      } else { 
       // and more errors 
      } 
     }, {perms:'email,user_birthday'}); // request your specific permissions here 
    } 
    return false; 
}); 

回答

1

我必须做同样的事情。我想出了这个:

 
$("#fb_login").click(function(){ 

      FB.login(function(response) { 
        if (response.session) 
        { 
         if (response.perms) 
         { 
           //alert("logged in..granted"); 
          var uid = FB.getSession().uid; 
         FB.api(
         { 
          method: 'fql.query', 
          query: 'SELECT name,email,pic FROM user WHERE uid=' + uid 
         }, 
         function(response) { 
         var user = response[0]; 
           $.get("addUser.php", { name: user.name, fbid: uid ,email: user.email }, function(data){ 
           // ajax call to addUser.php to insert into database. 


          }); 
          } 
          ); 
         } 
         else 
         { 
          // alert("Since You Have Not Granted Permissions For Accessing E-mails, You Can't register for any of the events."); 

         } 
        } 
        else 
        { 
         //alert("Not Logged In"); 
        } 
}, {perms:'publish_stream,email'}); // the extended permissions have to be specified here. 

您可以修改上述脚本以适应您的更改。 :)

+0

这几乎就是我所需要的,但我已经在这里结束了。这段代码实际上使用了REST API。当我使用JS SDK完成时,我会发布我的代码。谢谢! – 2011-05-05 06:52:34

+1

只需简单的说明,不需要调用'FB.getSession()。uid'作为会话对象中的id:'var uid = response.session.uid;' – ifaour 2011-05-05 18:07:27

1

权限对话框需要在弹出窗口或在Facebook的画布页面被加载,以防止点击劫持,因此没有,有没有办法做到这一点(虽然我很乐意被证明错误)。

,并澄清,通过弹出窗口,我的意思是在authentication documentation所示形式: FB auth dialog

可以火,当用户提交表单这个弹出,就像这样:

$('#submit_btn').click(function() // could also listen to the .submit() event 
{ 
    // show popup 
    FB.login(function(response) 
    { 
     // use FB methods to get data you want, 
     // attach it to valid input fields 

     // submit form 
     $('#form').submit(); 
    }); 
}); 
+0

是的,我认为这是我正在寻找的方法。将回复并确认何时根据需要进行工作。再次感谢你! – 2011-05-05 05:21:35

+0

我想这不是,但是你知道当有人点击页面上方的按钮时,如果不能重新加载页面吗? – 2011-05-05 07:22:00