. .

tutorial

Using the Smalltalk Facebook Interface

February 24, 2010 15:51:00.824

I've seen a few questions pop up on getting started with the Facebook interface I wrote, so I thought I'd post a basic "getting started" tutorial. First off, you need to go to the Facebook website (developer pages) and create an application definition - you'll get your application keys (you'll need those to make any Facebook API callls).

Once you've done that, start VisualWorks 7.7 (or ObjectStudio 8.2) and load the FacebookBundle from the public store repository.

Once you've done that, you need to execute the following code (use a workspace for now) with your application credentials:


"login"
holder := FacebookSecretHolder new
		apiKey: apiKey;
		secretKey: secret;
		applicationId: appId.

"now get the connection (will spawn a web browser"
connection := Connection withSecretHolder: holder.
connection login.

At the end of that, your default browser should pop up - it may show you what's below, or it may prompt you to login:

Once you've logged in, execute the following code to start a session:


"get auth token"
connection authGetSession.

At this point, you can start using the API - but you may notice that some calls don't work as you expect. For instance, #getStream will only return your news updates, and trying to publish to the news stream (#streamPublish:) will fail. Why? Well, your application needs to have permissions granted. Execute the following code, which will spin your browser back up, prompting you to authorize the relevant permissions:


"only need to ask for these authorizations once - grants permission to read news feed
and to write to the news feed"
connection grantExtendedPermissionFor: 'read_stream'.
connection grantExtendedPermissionFor: 'publish_stream'.

As the comment notes, you only need to do that once. Not once per session, once, period - unless Facebook changes something, or you use the APIs (or website) to revoke the granted rights. Now, use this to read the stream (inspect the results), and then publish an update:


"now read the news feed"
connection streamGet.


"update status in stream"
connection streamPublish: 'Writing to my Facebook news stream from Smalltalk!'.

Use the browser to verify that it all worked. That's pretty much it - to disconnect your session, use the code below:


"logout"
connection clearSession

You should be good to go. If anything seems wrong, just let me know

Technorati Tags: , ,

posted by James Robertson

 Share Tweet This