2

I have really simple few lines of Facebook app, using the new Facebook API:

<pre>

<?php

require 'facebook.php';

// Create our Application instance.
$facebook = new Facebook(array(
  'appId'  => '117676584930569',
  'secret' => '**********',                 // hidden here on the post...
  'cookie' => true,
));

var_dump($facebook);

?>

but it is giving me the following output:

http://apps.facebook.com/woolaladev/i2.php would give out

object(Facebook)#1 (6) {
  ["appId:protected"]=>
  string(15) "117676584930569"
  ["apiSecret:protected"]=>
  string(32) "**********"                   <--- just hidden on this post
  ["session:protected"]=>
  NULL                                      <--- Session is NULL for some reason
  ["sessionLoaded:protected"]=>
  bool(false)
  ["cookieSupport:protected"]=>
  bool(true)
  ["baseDomain:protected"]=>
  string(0) ""
}

Session is NULL for some reason, but I am logged in and can access my home and profile and run other apps on Facebook (to see that I am logged on).

I am following the sample on:

http://github.com/facebook/php-sdk/blob/master/examples/example.php
http://github.com/facebook/php-sdk/blob/master/src/facebook.php

(download using raw URL: wget http://github.com/facebook/php-sdk/raw/master/src/facebook.php )

Trying on both hosting companies at dreamhost.com and netfirms.com, and the results are the same.

1
  • Had exact same problem, looking for solutions :/ [no luck yet] Commented May 18, 2011 at 17:25

2 Answers 2

2

Session opened doesn't mean that you are logged to Facebook.

The session needs to be open in the concerned website, which means that you should add a "connect with facebook" button in your website and click it! then reload the page and you'll get your session :)

$session = $facebook->getSession();
$me = null;
if ($session) {
  try {
    $uid = $facebook->getUser();
    $me = $facebook->api('/me');
    $friends = $facebook->api('/me/friends'); //array of friends - for every friend you get id & name
  } catch (FacebookApiException $e) {
    error_log($e);
  }
}
Sign up to request clarification or add additional context in comments.

3 Comments

I just want to get friend's list and maybe photo thumbnail like the old API does. So the session is not needed for those? thanks.
It is needed. I'll edit my code for an example to get friends, but keep in mind that you will have to implement the login button to get a session.
what about all those apps that let you click "Allow (authorization)" and then next time you go to apps.facebook.com/someapp, it will just start the app and be able to get your friends list, etc, without need us to click the Login button?
1
$session = $facebook->getSession(); 

When you call this with the new graph api it says the method isn't there.

Fatal error: Call to undefined method Facebook::getSession() in /home/pri...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.