tags:

views:

41

answers:

1

:::::::::::::::::::::::::: Here's the Solution I ended up with ::::::::::::::::::::::::::

<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId   : '<?php echo $appid; ?>',
      session : <?php echo isset($session) ? "'".json_encode($session)."'" : 'null'; ?>, // don't refetch the session when PHP already has it
      status  : true, // check login status
      cookie  : true, // enable cookies to allow the server to access the session
      xfbml   : true    // parse XFBML
    });

        FB.getLoginStatus(function(response) {
          if (response.session) {
            // logged in and connected user, someone you know
          } else {
            // no user session available, redirect them to login
            window.top.location = "<?php echo $loginUrl; ?>";
          }
        });

    // whenever the user logs in, we refresh the page
    FB.Event.subscribe('auth.login', function() {
      window.location.reload();
    });
  };

  (function() {
    var e = document.createElement('script');
    e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
    e.async = true;
    document.getElementById('fb-root').appendChild(e);
  }());
</script>   

:::::::::::::::::::::::::: Here's the Original Question ::::::::::::::::::::::::::

I'm using the facebook php-sdk(2.1.2). All I want to do is what almost every FB application with req_perms has. the Stupid "REQUEST FOR PERMISSIONS" box to pop up when you install it.

I DO NOT wan't a button that the user has to push.

I DO NOT want a popup to appear.

I DO NOT want to use FBML, since they're doing away withit.

this is the standard FB permissions dialog that shows up where my app should show up in the Canvas Iframe.

I tried:

<?php if(!$me): ?>
<head>
<meta HTTP-EQUIV="REFRESH" content="0; <?php echo $loginUrl; ?>">
</head>
<?php die(); ?>
<?php endif; ?>

That for some reason showed a Facebook logo linked to the correct URL I wanted (NOT WHAT I WANT!)

<?php if($me): ?>
   window.fbAsyncInit = function() {
     FB.init({
       appId   : '<?php echo $appid; ?>',
       session : <?php echo isset($session) ? "'".json_encode($session)."'" : 'null'; ?>, // don't refetch the session when PHP already has it
       status  : true, // check login status
       cookie  : true, // enable cookies to allow the server to access the session
       xfbml   : true // parse XFBML
     });

     // whenever the user logs in, we refresh the page
     FB.Event.subscribe('auth.login', function() {
       window.location.reload();
     });
   };

   (function() {
     var e = document.createElement('script');
     e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
     e.async = true;
     document.getElementById('fb-root').appendChild(e);
   }());
 </script>
 <fb:redirect url="<?php echo $loginUrl; ?>" />
<?php die("</html>"); ?> 

This one showed a blank page.

<?php if($me): ?>
   window.fbAsyncInit = function() {
     FB.init({
       appId   : '<?php echo $appid; ?>',
       session : <?php echo isset($session) ? "'".json_encode($session)."'" : 'null'; ?>, // don't refetch the session when PHP already has it
       status  : true, // check login status
       cookie  : true, // enable cookies to allow the server to access the session
       xfbml   : true // parse XFBML
     });

     // whenever the user logs in, we refresh the page
     FB.Event.subscribe('auth.login', function() {
       window.location.reload();
     });
   };

   (function() {
     var e = document.createElement('script');
     e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
     e.async = true;
     document.getElementById('fb-root').appendChild(e);
   }());
 </script>
 <script>
 FB.login(function(response) {
     if (response.session) {
         if (response.perms.indexOf('publish_stream') != -1) {
             //User has logged in and given us publish_stream permissions
         );
         else {
             //User has logged in but not given us publish_stream        
         }
     }
     else {
     //User is not logged in
 }, {perms:'offline_access,publish_stream'});
 </script>

This one Also shows a blank page.

What I want isn't unpopular, but the FB documentation is the worst documentation I've ever come accross. Nothing works. Something this idiotically simple should not take 2 days to figure out.

A: 

Basically, you use the PHP sdk to get the login url and then do a javascript redirect to that url. This (http://github.com/facebook/php-sdk/blob/master/examples/example.php) example does everything for you except for the redirect. In the example they have a link you click to login. If you want it to be automatic do the following:

<script>
FB.getLoginStatus(function(response) {
  if (response.session) {
    // logged in and connected user, someone you know
  } else {
    // no user session available, redirect them to login
    window.top.location = <?php echo $loginUrl; ?>
  }
});
</script>
Nathan Totten
Awesome, I got it working The final code is now in my Question