Question

Let's say I own/control a Facebook page where events are posted. I'd like to display these events on another website (In my case, a WordPress blog, but that's not the important part) on an "Upcoming events" page.

What I'm unsure about is: Is the Facebook API usable "externally" like this? I've downloaded the PHP library and have a demo app running that works from within Facebook (i.e. emitting FBML that facebook.com interprets and displays to the logged-in user), but in my case I want a third party (my web server) to query Facebook every so often, rather than the site visitors directly requesting data (HTML/JSON/etc.) from Facebook itself.

Is this sort of thing possible with the Facebook API? How will my web server authenticate itself? What information do I have to store?

Note: I'm looking for information more at a "sequence diagram" conceptual level, not just asking for code. That part I can figure out myself. ;) Unfortunately, Google and the FB developer wiki have not been entirely forthcoming. What do I need to know so I can start coding?

Was it helpful?

Solution

This is a basic overview of how I've done it for a few of my clients who wanted similar functionality:

  1. Create a pretty basic app that prompts for Extended permissions, specifically "offline_access" and whatever else you need
  2. Store the resulting Session Key in your database with the UID
  3. Create a secure, authenticated webservice for your app which allows you to get the info you need for a UID that you supply, using the session that you've stored in your database
  4. On the website make requests to your app's webservice, being sure to cache the results for a certain period of time and only make a new request to your webservice once the cache has expired (I use 5-10 minutes for most of mine)

So basically your Facebook app acts sort of like a proxy between the website and the user, doing all of the authenticating and requesting using legitimate means.

I've used a webservice because I only wanted to maintain one Facebook app for multiple client's needs. It works like this (in a not-very-awesome ASCII art diagram):

Facebook User 1 \                    / Client Website 1
Facebook User 2  --- Facebook App ---  Client Website 2
Facebook User 3 /                    \ Client Website 3

Note: I've only done this for users, not pages, so your mileage may vary.

OTHER TIPS

AFAIK other than user info, you can't fetch any other data from facebook.

But you can try it other way - say create an app that stores events and other relevant information on a webserver and then your other website can easily access that info.

You can do Events.get with the Facebook API then supply the page/profile ID you'd like to get the events for. Depending on how your page is setup you may have to authenticate, simply use your Facebook account, since you should have access to all the events. oh and make sure you do plenty of caching so your not hitting Facebook on every page load.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top