$ facebook-> getSession () returns null in the sample code. this is normal?

Running the sample code for the Facebook API I get a null session object and I should get a non-zero object giving a comment in the code. What am I doing wrong?

In other words, in my index.php, this snippet from the example code shows "no session" when I go http://apps.facebook.com/my_appto my browser:

<?php

require './facebook.php';

// Create our Application instance.
$facebook = new Facebook(array(
  'appId' => '...', // actual value replaced by '...' for this post
  'secret' => '...', // actual value replaced by '...' for the post
  'cookie' => true,
));

// We may or may not have this data based on a $_GET or $_COOKIE based session.
//
// If we get a session here, it means we found a correctly signed session using
// the Application Secret only Facebook and the Application know. We dont know
// if it is still valid until we make an API call using the session. A session
// can become invalid if it has already expired (should not be getting the
// session back in this case) or if the user logged out of Facebook.
$session = $facebook->getSession();

if ($session) {
  echo "session ok";
}
else {
  echo "no session";
}


?>

Note: on my server index.php and facebook.php are in the same folder.

+4
source share
3 answers

Have you already linked your app?

if ($session) {
  $logoutUrl = $facebook->getLogoutUrl();
} else {
  $loginUrl = $facebook->getLoginUrl();
}
 <?php if ($me): ?>
<a href="<?php echo $logoutUrl; ?>">
<img src="http://static.ak.fbcdn.net/rsrc.php/z2Y31/hash/cxrz4k7j.gif">
</a>
<?php else: ?>
<div>
Using JavaScript &amp; XFBML: <fb:login-button></fb:login-button>
</div>
<div>
Without using JavaScript &amp; XFBML:
<a href="<?php echo $loginUrl; ?>">
<img src="http://static.ak.fbcdn.net/rsrc.php/zB6N8/hash/4li2k73z.gif">
</a>
</div>
<?php endif ?>

Code taken from the link you provided.

+3
source

, # 8 http://forum.developers.facebook.net/viewtopic.php?pid=267627

. "standardcombo".

.

  • " "
  • " "
  • > > "OAuth 2.0 ()"
+3

, , , . facebook, . , , - , , facebook. , .

, , , , URL- . ( URL-, "return_session = 1".) , .

, , , . , http://forum.developers.facebook.com/viewtopic.php?id=56789, 7 2010 ( ).

, , , , , "" , , . , URL canvas , .

, ; , :

landing page:
    if the facebook api token is not loaded,
        redirect to the authorization url
    try to load the user id // to validate that the session
    if the user id is not loaded,
        redirect to the loginurl from the facebook api
    // if it reaches here, then we have both an api token and a session

authorization page:
    get authorization token // see the post for how to do that
    redirect back to the page configured as the canvas url

Maybe a better way, and I'm sure someone more familiar with this than me could get a better solution or post a generic code.

+1
source

All Articles