Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting user data after the Facebook login

I have this page where I am doing testing

http://www.comehike.com/test_fb_connect.php

The button works fine - it lets me log in and out of Facebook, but I don't know anything about this user, so its kind of pointless.

What I need to do it pull their first_name, last_name, email, lat, lng from their FB. I had code like this before, but it just broke my site:

$message = "Apps on Facebook.com are cool!";

$feed_url = "http://www.facebook.com/dialog/feed?app_id=".$app_id."&redirect_uri=" . urlencode($canvas_page)
                . "&message=" . $message;

 if (empty($_REQUEST["post_id"])) {
    echo("<script> top.location.href='" . $feed_url . "'</script>");
 } else {
    echo ("Feed Post Id: " . $_REQUEST["post_id"]);
 }

What can I do to pull the data I need for the account?

By the way, my FB login button setup looks like this:

<div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#appId=my_id&amp;xfbml=1">
</script><fb:login-button show-faces="false" perms="user_hometown,user_about_me,email,user_address" autologoutlink="true" width="200" max-rows="1">
</fb:login-button>

Thanks!

like image 973
Genadinik Avatar asked Jul 29 '11 16:07

Genadinik


1 Answers

Once the user is authenticated you can make graph calls against the special me object:

PHP

$json = file_get_contents('https://graph.facebook.com/me');
$detailObj = json_decode($json);
var_dump($detailObj);

JavaScript

FB.api('/me', function(response) {
  alert(response.name);  //response is the basic user object
});

More on FB.api

More on available graph objects

like image 166
shanethehat Avatar answered Sep 22 '22 06:09

shanethehat