views:

1509

answers:

4

Facebook Connect

I have spent a few weeks putting together a basic web site which uses Facebook connect as authentication.

I have studied 'theRunAround', the provided example application. However the code is convoluted and uses a large number of files and classes, most of which have a lot of functionality that I have no need for. I have also had a good read of the documentation.

My code works almost all the time. However, occasionally I receive strange, unpredictable errors.

Required Features

  • Check if user is already logged in to Facebook, if so, retrieve the fb_uid, name, profile pic
  • Return a list of friends which have also connected to this application

Are there any tutorials, better than the ones provided by Facebook regarding such simple functionality?

A: 

Here is a pretty detailed tutorial. Note that i have not tried this but i have used other code from pakt and its been pretty helpful.

Ólafur Waage
+2  A: 

I have recently added a friend notification feature to Cogenuity using the facebook connect technology.

First, you need to create the facebook object in your php code. I am assuming that you have already done the facebook application registration goodness. I found a lot of the parts to facebook connect not to work but what did work was this.

$user = $facebook->require_login();

I found that the FQL parts worked pretty good.

$query = "select uid1 from friend where uid2 = {$user}";
$results = $facebook->api_client->fql_query($query);

I used this FQL query which may serve your needs.

$query = "SELECT name, pic_square, status, about_me FROM user WHERE uid = {$uid}";
$results = $facebook->api_client->fql_query($query);

As does the notification_send method.

$facebook->api_client->notifications_send($notifyTarget, $intro, 'user_to_user');

I hope this helps.

Glenn
+2  A: 

I wrote my own library to work with Facebook Connect as I found the one provided to be very lacking.

I can't provide the code as it is company code, but here's a breakdown of what I needed to do. Hopefully you can use it and fill in the blanks easily yourself.

  1. In your application settings, configure the "Connect" tab. The "Connect URL" in my case is the root folder where my xd_receiver.htm file is. Also, under "Advanced" I marked my app as a Web Application.

  2. Put your xd_receiver.htm file in the root folder specified above. There is a ton of documentation on xd_receiver.htm out there. This is what facebook hits when the user logs in. It will write cookies to their browser which your application can read in later to do authentication.

  3. The cookies Facebook sets are in the format of _ where APIKEY is your apps API key and is the name of the cookie. You'll need the _session_key cookie to make further API calls. If this cookie is not set, you need to show the login button as desscribed in steps 4 - 6. Otherwise skip to step 7.

  4. You need to load in the Facebook javascript file on your page that you will have the FB login button. ==> http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php

  5. To show the FB login button, use: The Facebook JS will automatically render a facebook login button for you. It will trigger the "facebook_onlogin" method that you shall define once the user is logged in so you can do something after they login.

  6. Right below the above markup, you need to call the FB init javascript to have it render the button:

    FB.init('YOUR API KEY HERE', 'ABSOLUTE PATH TO YOUR XD_RECEIVER.HTM FILE HERE');
  7. Use the session_key as set in the cookie to make any API calls. How to make API calls is well documented.


Hope this helps.

Matt
A: 

Hey guys,

I wrote a small tutorial on using facebook connect with your existing PHP web app... It's very simple and just needs a small aleration to your database + call stack. The link is below.

http://blog.sankhomallik.com/2009/06/24/add-facebook-connect-to-your-php-web-app/

It doesn't go into the API or how to use the Facebook platform to spruce up your site - it just covers the basics of how to get someone to signup to your site using facebook connect.

  • Sankho