views:

245

answers:

1

I have implemented the following code below according to the documentation and can get it to connect and display user id...

<?php

define('FACEBOOK_APP_ID', '87939462878');
define('FACEBOOK_SECRET', '1ab6346bc51329831998985aba200935');

function get_facebook_cookie($app_id, $application_secret) {
  $args = array();
  parse_str(trim($_COOKIE['fbs_' . $app_id], '\\"'), $args);
  ksort($args);
  $payload = '';
  foreach ($args as $key => $value) {
    if ($key != 'sig') {
      $payload .= $key . '=' . $value;
    }
  }
  if (md5($payload . $application_secret) != $args['sig']) {
    return null;
  }
  return $args;
}

$cookie = get_facebook_cookie(FACEBOOK_APP_ID, FACEBOOK_SECRET);

?>

<?php if ($cookie) { ?>
      Your user ID is <?= $cookie['uid'] ?>
    <?php } else { ?>
      <fb:login-button show-faces="true" perms="email,user_birthday,user_location"></fb:login-button>
    <?php } ?>


<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"&gt;&lt;/script&gt;
    <script>
      FB.init({appId: '<?= FACEBOOK_APP_ID ?>', status: true,
               cookie: true, xfbml: true});
      FB.Event.subscribe('auth.login', function(response) {
        window.location.reload();
      });
    </script>

<?php
$user = json_decode(file_get_contents(
    'https://graph.facebook.com/me?access_token=' .
    $cookie['access_token']))->id;
print_r($user);
?>

However, if I use:

$user = json_decode(file_get_contents(
    'https://graph.facebook.com/me?wrap_access_token=' .
    $cookie['oauth_access_token']))->me; //or $cookie['access_token']))->me;
register_user($user->id, $user->email, $user->name, $user->username,
              $user->birthday_date);

to get the email address, I keep getting file_get_content errors. I also get errors saying it doesn't recognize the register_user function. I feel that I'm close!! Please help if possible, thanks!

A: 

I'm not familiar with the library you're using that has register_user, but is there any reason you aren't using the Facebook connect PHP SDK? You can download it at http://github.com/facebook/php-sdk and it has examples for both obtaining the auth token with extended permissions and then pulling all the user information you seem to want.

Ryan Garcia
the register_user is in their example:http://developers.facebook.com/docs/guides/web#loginunder "Account Registration Data"i will try the php sdk and see if it works out better, thanks!
Hooman Ahmadi