views:

669

answers:

1

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  A: 

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);
  }

}

Soufiane Hassou
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.
Soufiane Hassou
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?
動靜能量