Adding Comments in your Site with the Facebook API

Now that I have jumped almost 2 weeks without a post, as I have been super busy, this should have been a real easy item to post, but I wanted to make sure that this is done correctly. This is probably one of the easiest methods to add some great Facebook functionality in your site. This revolves around comments to a page. In my example, I am posting topics to discuss. This is mainly just a small little blurb that I will enter via an admin form on the site, and then list the different topics for everyone to select one. Once they select it, they can view the details of the topic and then comment on it using the Facebook API/Social plugin. So as always, lets go through a basic plan for this idea.

1. The model is Topic, with a table in the DB labeled “topics”
2. Only the admin has access to add or edit the topics
3. All comments on this topic will be done through the Facebook API/Social Plugin Comments
4. Topics will have a title that will also double as the Unique ID (to be explained later)
5. Topic titles, or themes, will not be allowed to be edited, to be explained why later
6. Administration of the comments will be done by the Facebook Application admins, which differs from the site admins
7. Start Dates will determine if the topic is allowed to be visible yet
8. End dates are optional, and will be built upon later with more advanced FBML/FB JS libraries

And there it is, some basic ideas behind the whole idea. So now lets get into some of the items called out in Numbers 4 and 5
Continue reading Adding Comments in your Site with the Facebook API

Facebook Privacy and Common Sense

This post is just a quick reminder of common sense that should be on every application. Whether it is a Facebook application, a Twitter application, or just a connected application via webservices, you should never expose sensitive data. I mention this because of my previous post which shows how to connect Facebook to a CakePHP application. Even though this is using the basic ideas and examples from the Facebook SDKs, does not mean that this common sense should be disregarded.

An excerpt from a Facebook Developers blog, located at:
http://developers.facebook.com/blog/post/418

Our policy is very clear about protecting user data, ensuring that no one can access private user information without explicit user consent. Further, developers cannot disclose user information to ad networks and data brokers. We take strong measures to enforce this policy, including suspending and disabling applications that violate it.

Recently, it has come to our attention that several applications built on Facebook Platform were passing the User ID (UID), an identifier that we use within our APIs, in a manner that violated this policy. In most cases, developers did not intend to pass this information, but did so because of the technical details of how browsers work.

It is important that when you develop a Facebook application, you adhere to the policies. Remember to take a common sense approach, and make sure you do not violate any security policies.

Facebook Application on the Site

OK, I finally got my data models set up and working. I have the initial CakePHP set up on the site, it is using v1.3, and now I am ready to set it up for the Facebook integration, and start to add the integration. When we first set up the application on the Facebook side, I chose to do an “iframe” version of the application, as I want Facebook on my site, and be able to have integration with some of the great Facebook tools on the site, and be able to “promote me”. And remember this is just a way to show a possible real world example of how to integrate these things with your site. Actual applications may vary, but this is the base to integrate. At least, as of this posting it is the base, it may change in the future.

So lets go ahead and dive into it. If you do not have the application ID for your Facebook application, you can get it at the following:
http://www.facebook.com/developers/apps.php

The next thing is to grab the API and code from Facebook. This can be found at the following page:
http://developers.facebook.com/docs/

This is the main page, and you will need to scroll to the bottom of the page. This will list different APIs that are available. I am going to be using the PHP and JavaScript SDKs. This will provide the back end that I will want, and will also provide a positive user experience on the front end. So be sure to download both SDKs.

After that, now we need to start getting some stuff set up. In this post, I am just going to explain how to get this set up, and working right now. It is important that we get the correct items working, and so we will be working with the “pages” area for the JS SDK, and creating a very simple controller for the PHP SDK so we can get set up and running. I am just using, for right now, the base CakePHP CSS styles and layouts. All we need is a page to display some of the basic items to ensure that we have installed the SDKs in the proper locations. So lets go.
Continue reading Facebook Application on the Site

Its the Simple Things

I am still working forward on the Facebook integration and resume stuff. And will get that posted when I have completed the data model and the basic set up. I will also post about how to integrate Facebook into a CakePHP application. But in the mean time, there was something that happened, that I thought may help me remember.

The other day I was working on an application with a simple login check and display of an error message. I would test the login function with a correct account and an incorrect account. It was driving me batty as when I logged in with wrong credentials, it would not give me the message that something was wrong. I was checking everything. I checked the controller, the model and the view. Could not pin point the issue. I could not find anything wrong. Here is what I had in the view:

if ($sess->check(errors)) {
    $sess->errors);
}

Basically, if the login is incorrect, it will set an error. The session object will read any errors, set the item in the session to display once, and then kill the error so it does not keep happening. And here is the problem, in another application using the same basic code it works fine. Could not pinpoint why this is a problem here. Until I took a brief walk away from the desk. Then I came back and understood what I needed to do.

The check function does not do any displaying of any kind. It is supposed to check the session for errors, and destroy the session element with the errors. Before it does that, it sets a variable for the errors. However, it does not display. I needed to alter it to this:

if ($sess->check(errors)) {
    echo $sess->errors);
}

And there it was! Wow, the littlest thing. I am reminded of a Simpsons episode in which Hank Scorpio tells Homer:
“Well, you can’t argue with the little things. It’s the little things that make up life.”

Indeed it does.