views:

1201

answers:

2

in this simple php file: (http://gist.github.com/273402)

<?php
session_start();
include_once 'libraries/facebook/facebook.php';

//$fb_user=$facebook->get_loggedin_user();
?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml"&gt;
<head>
<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/en_US" type="text/javascript"></script>
<script type="text/javascript">
    FB.init("PUBLIC_KEY", "http://localhost/xd_receiver.htm",{"reloadIfSessionStateChanged":true});
</script>
</head>
<body>
<h1>User index</h1>
<fb:login-button onlogin="window.location.reload(true)"></fb:login-button>
<fb:profile-pic uid="loggedinuser" size="square" facebook-logo="true"></fb:profile-pic>
<?php
$facebook = new Facebook("PUBLIC_KEY","SECRET");
    if($facebook->get_loggedin_user()){
      echo "logged";
    } else {
      echo "not-logged";
    };

    ?>
</body>
</html>

i cannot get $facebook->get_loggedin_user(), but FBXML do render the profile pic, why?

how can i get the user info in PHP, not in JS?

A: 

it seems you cannot use localhost as domain/test platform.

change localhost to a valid domain in fb application settings, and change the http://localhost/xd_receiver.htm to sth valid

joetsuihk
actually, you can edit host file to do development in localhost. map test.com to 127.0.0.1, and in fb application settings, change the domain and application callback to test.com will do the job
joetsuihk
A: 

you can retrieve many information using "users_getInfo":

$user_details=$fb->api_client->users_getInfo($fb_user, array('last_name','first_name','pic_square'));

But you first have to get the login to work. Did you create the application on facebook? did you copy the xd receiver? I don't know if localhost is allowed.

Here is a tutorial I wrote.

Pons