#52WeeksOfCode Week 21 – Facebook API

Week: 21

Language: Facebook API

IDE(s): TextWrangler with MAMP

History (Official):

(From Facebook’s Facebook page)

“Founded in 2004, Facebook’s mission is to give people the power to share and make the world more open and connected. People use Facebook to stay connected with friends and family, to discover what’s going on in the world, and to share and express what matters to them.”

History (Real):

Letting us connect with friends and family and all of the other sharing and caring doesn’t pay the bills.

Facebook makes money by selling the attention of its users.  If that’s a problem for you, don’t get an account.

That’s pretty much all I have to say about that.

Discussion:

Officially, Facebook provides SDKs (Software Development Kits) for IOS, Android, Javascript and PHP. There are also third-party providers that offer support for other languages such as Objective-C, Java, Ruby, Python and Flash. Facebook does not offer support for these third-party kits.

I like to keep things simple, so I’ll be using the Facebook Javascript SDK. There is no software to download or install. You simply need to add a short section of code to your Web page. When the page is loaded into a browser, the Facebook SDK will automatically load itself.

First I need to get Facebook to recognize me as a developer. I select Register as a Developer from the Apps menu on http://developers.facebook.com (after logging in with my Facebook account). I’m asked to re-enter my Facebook password.

FB Password Verification

Password Verification

I agree to Facebook’s policies.

FB Policy acceptance

Facebook Policy Acceptance Dialogue

I’m asked to confirm my registration by entering a code that will be sent to my phone by either a text message or a phone call. Facebook seems to be unable to text to my phone for some reason, so I picked Send via Phone Call. In a few moments, my phone rang and a friendly automated voice told me my code.

Account Verification Code

Account Verification Code

Finally I was successfully enrolled as a Facebook developer. I haven’t written a lick of code yet but I still feel like I’ve accomplished something.

Now I need to get an ID and secret token for my app. These identify my software to Facebook so they can manage what I can and can’t do and also keeps other developers from pretending to be me. (Twitter and other social networking services have similar methods.)

After a couple of false starts (my app title contained a trade name, which is verboten), I was sent to a page which provided the Javascript code (whichincluded my app ID and secret token) to insert in my Web page to load and initialize the Facebook API.

I created a page called fb_test.html and saved it in my MAMP local site folder. I inserted a bit of code to add a Like button on the page, loaded it up and it worked!

Testing the Like Button

Like Button Test Successful!

So far, so good. Now I’d like to send a message to Facebook from my page. I replaced the Like button code with the code for a Send button. A quick page reload later and voila:

Send Button Load

Loading the Send Button

Now to compose a message to myself:

Composing a Send

Just saying hi….

Meanwhile, over on my Facebook account:

Message received

Hey! I got a message!

Overall, it was a very pleasant experience. Granted, I wasn’t doing anything complicated, but I appreciated the hand-holding. Sample code was easy to find and worked first time. The documentation was readily available and easy to browse.

I almost hate to say it, but this was probably the most pleasant developer experience I’ve had to date. Whatever your opinion of Facebook, and everyone’s got an opinion, I can’t fault them here.

Advertisements

#52WeeksOfCode Week 20 – Qt

Week: 20

Language: Qt

IDE(s): Qt Creator

 

History (official):

(From the Qt Project ‘About Us’ page)

“Qt (“cute”) is a leading cross-platform application and UI development framework for leading desktop, embedded and mobile operating systems. Qt uses standard C++ and is widely used for developing software applications with a GUI and also for developing non-GUI applications with features such as file handling, database access, XML parsing, thread management and network support.

Qt’s powerful full-framework capabilities allows for the creation of highly-performing native applications as well as for hybrid development where the developer can choose which tools provide the best user experience.

Qt is created by developers for developers where making developers’ lives easier is top priority. We strive to provide an incomparable developer experience with the tools necessary to create amazing user experiences. Qt is platform agnostic and believes in making sure that all developers are privy of being able to target multiple platforms with one framework by simply reusing code. We believe in providing freedom to the developer. Code less. Create more. Deploy everywhere.”

History (real):

Qt allows C++ developers to create modern-looking GUI applications without having to learn more current languages such as C#.

(NOTE: I have no problem with C++. It was my first object-oriented language and I’ll always have a soft spot for it in my nerdy heart.)

The code is quite portable between different operating systems, making rapid, cross-platform deployment straightforward.

BUT…there’s a price.

In programming, as in life, you get nothing for free. The cost of portability is that you can’t rely on any particular operating system to do things for you. For example, Windows may have a perfectly fine software routine for rendering a menu, but you can’t use it. If you do, then you’ll have to rewrite your code every time you want to run your application on a different operating system that uses different code for menu-rendering. In a related issue, you have to include the code libraries that your applications uses because you can’t assume that your target computer (even if it runs the same operating system) has them.

Because of this, Qt has to reinvent the wheel for almost everything it does.

Another consequence of this independence is that the owners of the operating systems you’re targeting are always ahead of you with shiny new graphics features and new hardware. As a result, your applications are always going to look kind of shabby compared to the ones that are native to the platform. (Java has a similar problem.)

That being said, I like the idea of Qt. Cross-platform, particularly for a rich development framework, is a good thing.

It turns out that the reality fell a bit short.

 

Discussion:

Though Qt works with different IDEs (including a plain old text editor), I decided to use the native development environment Qt Creator. It’s free and since it pulls the install files from the Internet, the installer is a quick download. Since Qt is by definition a stranger wherever it goes, I decided to use Mac OS X as my development platform.

I fired up Qt Creator. It seemed straightforward enough, with plenty of documentation and tutorials.

QT Creator GUI

QT Creator GUI

I decided to go with a simple graphical application project. I typed in the project name, chose a folder for it and clicked on Save.

My project was nowhere to be found. It wasn’t in Qt Creator. It wasn’t in the folder I had created. Not only that, but the menu selection to create a new project was now grayed out.

(“I felt a great disturbance in the Force, as if millions of voices suddenly cried out in terror and were suddenly silenced.”)

Not a promising start.

I quit Qt Creator and re-started it. This time after naming the project, I just accepted the defaults. Now my project showed up. Now I just need to build and run it.

Hello World in Qt Creator

Hello World in Qt Creator

After a bit of searching in the documentation, it seems that I need to set up a Build and Run Kit.

After a bit more searching, it looks like I have to drop down to a command line and type in a bunch of code to create the kit by hand. You know, just like the Founding Fathers because FREEDOM.

I’m not going to do it.

I’m not stupid. I have all of the developer tools installed. I don’t have a problem typing commands in a terminal. I understand the reasons that this is happening is that Mac OS X deploys applications as self-contained packages and since Qt has its own code libraries, I have to hand-carry the bits into a package, as it were.

This is 2014. You offer me a graphical code editor that produces graphical applications on a modern operating system. If you can’t let me develop, build and run from the GUI out of the box with your own IDE, then I’m done with you.

I realize that at this point thousands of Qt developers are probably lining up outside my door to punch me in the throat, BUT…

If I was a professional Mac developer, with experience using XCode, Xamarin, Eclipse and even Visual Studio (which I have), what POSSIBLE reason could you give me to try Qt after this experience?

This is fixable, fellows. Get on it.