views:

1514

answers:

5

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 got 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?

+3  A: 

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.

Arpit Tambi
+3  A: 

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.

Tom
+4  A: 
Jason Berry
is the webservice adding much value in this set up?
klochner
I've used a webservice in my case because I have multiple clients using the one Facebook app, and those same clients' websites talking to the Facebook app to display the data on their own sites. If the website and the app were one in the same then you could eliminate the web service bit. As I said in my answer, this is just MY setup. Brant could do something similar and eliminate the bits he doesn't require.
Jason Berry
thanks, just curious - thought you might see some speed improvements by caching locally with the webservice, but seems like a lot of added complexity if you're not pulling a lot of data.
klochner
Jason Berry
I'm definitely going for a simple solution here, so I'll probably skip the web service bit, but this is useful information. For a while I thought I'd have to use Facebook Connect to do this sort of thing, I'm glad to see that there's a solution that just makes use of the basic Platform.
Brant Bobby
A: 

anyone able to provide a bit of code for this? Not very good at code and would rather use something that works...

A: 

I'm trying to get the events created on the facebook page for a public radio show to appear on the show's website.

I'm trying to use the Javascript SDK to query the events being attended by the dummy admin user that I use to manage the public page in the hopes that I can use that uid to access the event information and display it. I've got one event set up and the user is currently the only one attending it, but when I query the event_member table nothing comes up. I can get the user name and the event name to appear, but not any relationship between the two.

I just started with fb development in the last couple days and the API documentation is short on examples so I'm having some problems. I'm probably using the wrong method for accessing the dataset returned since eventually I'm going to have to loop through multiple rows, but for now I'm just trying to get some basic information printed out so I know that much works before I move on.

Here's my app so far. I can only get anything to display when I remove the third event_member query. Any input is most appreciated!

    <h1>Here On Earth</h1>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"&gt;&lt;/script&gt;
<script>
    window.fbAsyncInit = function() {FB.init({appId: '166023043414927', status: true, cookie: true, xfbml: true});};
    var user_id = "535781350";
    var query = FB.Data.query('select name, uid from user where uid={0}', user_id);
    query.wait(function(rows) {document.getElementById('name').innerHTML ='Your name is ' + rows[0].name;});

    var event_id = "165995390077907";
    var query = FB.Data.query("select name from event where eid={0}", event_id);
    query.wait(function(rows) {document.getElementById('event').innerHTML ='Your event is ' + rows[0].name;});

    var query = FB.Data.query("select name from user where uid in (select uid from event_member where eid={0})", event_id);
    query.wait(function(rows) {document.getElementById('event_member').innerHTML = rows[0].name + ' is attending your event.' ;});
</script>
Name:<div id="name"></div>
Event:<div id="event"></div>
Event Member:<div id="event_member"></div>
LeeAnn