views:

583

answers:

4

Hello guys,

I've started working on integrated Facebook Connect with my app. I have a slight lack of knowledge problem though.

I can perfectly make it so you log into Facebook Connect on my site, etc, shows your details all FB Connect functions work. But, how do I make it so I can store the facebook user ID into my MySQL database as part of the current users information? So how I can auto log them into Facebook Connect if they have granted access?

Thanks!

A: 

It is not possible to automate login to Facebook. Even if you found a way to do so, it would be in direct violation of the Facebook Platform terms of service.

Dustin Fineout
I think he just means "re-login" the user to his local site if the user remains logged into facebook.
Typeoneerror
I don't think so. James, what mean you sir?
Dustin Fineout
+1  A: 

Using the PHP Facebook client library, you should be able to add something this at the top of "the page":

$api_key = "YOUR APP API KEY";
$api_secret = "YOUR API SECRET KEY";

$facebook = new Facebook($api_key, $api_secret);
$facebook_id = $facebook->get_loggedin_user();

If the user is logged in, $facebook_id will be set to their facebook id (BIGINT). If not, it'll be null. Mind that users need to have third-party cookies enabled in their browser for this to work past the intial "connect" call. In that case you can use the API to get the logged in user:

$facebook->api_client->users_getLoggedInUser();

So basically (pseudo):

if (!is_null($facebook_id))
{
    // authenticate user on your site with local cookie or session
    // pull user data from users table by "$facebook_id"
    // if user isn't in the database, create a new row with their facebook id
}
else
{
    // show the connect button?
}
Typeoneerror
A: 

Have you looked at clickpass.com? Let's you log into your site with lots of different ids. Justing installing on a python site and takes a while but looks good.

+2  A: 

You have to create new users into your site during the facebook login process, so you can use the data saved next times. You have to modify your user table and add some fields for new data (such as the facebook id). I wrote a tutorial about it wiht PHP and MySql:

http://www.barattalo.it/facebook-connect-tutorial/

Pons