tags:

views:

532

answers:

4

I'm working on a project synching a facebook application with a regular website.

The db has got a users table, but the table only has got the user ID of each user of the application. The user id is the facebook user id of the people.

For each user in the users table, I need to fetch their name, and other info from facebook. The client is using a facebook application, so I believe he should have a developer key, and anything else needed.

My question is, how can I retrieve the users' name and other info from facebook using their facebook user id?

+1  A: 

With the following FQL statement:

SELECT name FROM user WHERE uid=211031

For more details read http://wiki.developers.facebook.com/index.php/FQL

hanno
+3  A: 

First of all make sure that your plan is d'accord with the Facebook Developer Policy.

you cannot store data you receive from Facebook, except certain "Storable Data".

http://wiki.developers.facebook.com/index.php/Platform_Policy_Overview#6._Storing_and_Using_Data_You_Receive_From_Facebook

To answer your Question.

The hack way:

A Batched FQL statement for several Users should do the trick. You can either use the API Function (also batchable) or the API Call for FQL Queries.

The better and more feature-rich way:

You want to Connect your Website to Facebook. What you are actually looking for is Facebook Connect.

Facebook Connect is simply said a Javascript Layer that replaces Placeholder tags. With Facebook Connect you are able to say <fb:photo pid="54321" uid="6789"></fb:photo>. or in your case

Andreas Klinger
In order to execute the FQL statement or have the `<fb:photo>` statement be parsed correctly, what url/libraries do I need to include?
Click Upvote
Nothing happens to the `<fb:photo>` command when I run it, I think it only gets processed if its run on the facebook.comserver, however I will be running it off-site and not as a facebookapp. Thoughts?
Click Upvote
as said you want to look into facebook connect
Andreas Klinger
+1  A: 

If you want to just show someone's name, this is a quick and easy way

<fb:name useyou='false' uid=".'"'.$values[$index]['userid'].'"'." />

Note: This code is used in a for loop, and the user db information was put into an array since I was expecting multiple rows.

An easier way to get user info than messing with FQL is using their API

I think this is the API you want http://wiki.developers.facebook.com/index.php/Users.getStandardInfo

Paul
Since I couldn't give links to everything due to my user status, exploring the wiki can do wonders.
Paul
+1  A: 

require_once('facebook-platform/client/facebook.php');

$facebook = new Facebook(API_KEY, SECRET);
$facebook->require_login();

function getInfo($user_list, $fields) 
{
    try
    {
        $u = $facebook->api_client->users_getInfo($user_list, $fields);
        return $u;
    }
    catch (FacebookRestClientException $e)
    {
        echo $e->getCode() . ' ' . $e->getMessage();
    }
}

Do something like that, $user_list is a list of UIDs and $fields is a list of all userInfo fields you want to retrieve from Facebook.

Look at the Facebook API.

Pierre-Antoine LaFayette