Facebook API Authentication

I can't find specifically the piece of information that I want.
I am building a website, that I also want to integrate into facebook as an application.
On my website, I want a user to be able to login to my site using only their facebook credentials which upon success returns their user Id (or whatever) which i can use in my application.
First question - is that possible!!!

If the user chooses to login to my application using their credentials which generates the account in my system, can I have the user automatically have the my application added to their profile?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi jdav357,

Regarding integrating with Facebook login credentials, yes this is possible and is available as a solution from Facebook.

Before you go any further may I suggest you have a look at Facebook's integration API which is available here: http://developers.facebook.com/get_started.php

It will provide you with good information about how to integrate, minimum requirements, and application authentication.

Good Luck!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
I would seriously hope that it is the exact opposite.

If I had a facebook account (which I do not) then I would be ***beyond*** stupid if I signed up on another unrelated web site by giving them my facebook login and password.... and facebook tells you it is valid and gives you the user id....

So what stops you logging all this and then having everyones facebook login ids.

If FB did allow that (which they do not) then I would cancel my account (which I dont have)
jdav357Author Commented:
Hi both, thanks for your comments.

Esdter, If I am correct I think it is possible to get the users id, I have attached the code off FB's site, this piece will get it:
<?php if ($cookie) { ?>
      Your user ID is <?= $cookie['uid'] ?>
    <?php } else { ?>
nbandan has provided a link to the API:

This is the way I think the likes of dailymotion.com do it. The user id then allows you to view bits of a users profile.

I am not the greatest at understanding documentation, so please correct me if you think I am misunderstanding the above. :-) thanks again for your help...


define('FACEBOOK_APP_ID', 'your application id');
define('FACEBOOK_SECRET', 'your application secret');

function get_facebook_cookie($app_id, $application_secret) {
  $args = array();
  parse_str(trim($_COOKIE['fbs_' . $app_id], '\\"'), $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);

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
    <?php if ($cookie) { ?>
      Your user ID is <?= $cookie['uid'] ?>
    <?php } else { ?>
    <?php } ?>

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

Open in new window

jdav357Author Commented:
Ps. I dont think the user gives the login details directly to an unrelated site, it navigates them away through some kind of popup etc, which allows a user to login directly to FB and then sets the cookie. Upon returning back to the site, the cookie is set along with a signature and a user id. Then you can go grab whole heaps of data about the uesr from their FB account (with their permission of course!)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.