开发者

Cannot get a session with Facebook app? (using its Graph API)

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 开发者_Python百科companies at dreamhost.com and netfirms.com, and the results are the same.


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


$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...

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜