开发者

Facebook iFrame app - displaying FB:ui depending on whether a user is logged in or not?

开发者 https://www.devze.com 2023-02-22 15:27 出处:网络
I\'m creating an iFrame app on Facebook which is basically just a Mailing List sign up page. However, when people click Sign Up, the FB:ui "Post To Your Wall" pops up and gives the user the

I'm creating an iFrame app on Facebook which is basically just a Mailing List sign up page. However, when people click Sign Up, the FB:ui "Post To Your Wall" pops up and gives the user the option to share what they have just signed up for if they want to. It works fine.

However, I want to find a way to display the FB:ui ONLY to users who are logged into Facebook. My app shouldn't require any permission from users as it is simply a landing page that gives people an option to share if they want to. There's never any automatic sharing done.

I'm using the below code currently:

<div id="fb-root"></div>
      <script src="http://connect.facebook.net/en_US/all.js">
      </script>
<script>
      开发者_JAVA百科   FB.init({ 
            appId:'my app id', cookie:true, 
            status:true, xfbml:true 
         });
         
         FB.getLoginStatus(function(response) {
if(response.session) {
sharethisnow();
} else {
// no user session available, someone you dont know
if(response.status == "notConnected") {
// But user is logged into facebook
sharethisnow();
} else {
// User is not logged into facebook
}
}
});

function sharethisnow() {
         FB.ui({ method: 'feed',  
            link: 'my link',
            name: 'my page name',
            caption: 'my caption',
            description: 'my decription',
            picture: 'my picture',
            message: 'my message'});
            }
      
      </script>

As you can see, I'm attempting to run the FB:ui (sharethisnow function) only to users who are either logged into Facebook AND my app, or logged into Facebook only. But for some reason the code above is only working for page-admins. When I log in as an admin, I sign up and the FB:ui pops up as it should do. However, when I view the page as a non-admin (just a general logged in Facebook user), the FB:ui pops up but says that there is an error and to "please try again later".


It's working fine for me, maybe check the Page settings (private/public). Also try this simpler code first:

<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
 FB.init({ 
    appId:'APP_ID', cookie:true, 
    status:true, xfbml:true 
 });

FB.getLoginStatus(function(response) {
    if(response.status == "unknown") {
        return;
    }
    sharethisnow();
});

function sharethisnow() {
    FB.ui({
        method: 'feed',
        message: 'my message'
    });
}
</script>
0

精彩评论

暂无评论...
验证码 换一张
取 消