[wp-hackers] Facebook Events Integration

Otto otto at ottodestruct.com
Wed Mar 10 16:18:56 UTC 2010


On Tue, Mar 9, 2010 at 8:39 PM, Jeff Waugh <jdub at bethesignal.org> wrote:
> Have a look at the "Simple Facebook Connect" plugin, which is designed to be
> a starting point for connecting WordPress and Facebook (with a few handy API
> and integration bits and pieces thrown in).

Thanks for the plug. :)

http://wordpress.org/extend/plugins/simple-facebook-connect/


On Tue, Mar 9, 2010 at 7:53 PM, Eric Mann <eric at eamann.com> wrote:
> 1)      This is the biggie . Even though the user is logged in to Facebook,
> WordPress isn't.  So when WP tries to post data to the FB application,
> everything fails.  Unfortunately I don't know how to trick the servers into
> recognizing one another or how to get WordPress to authenticate as a
> Facebook user.  If I can't do that, I can't create the event . any ideas?

You need to get a non-expiring session key from Facebook and store it.
This is a tad complicated, but here's the gist of it:

1. You need to use Facebook Connect javascript code to popup a
permissions dialog to the user somewhere. Specifically, you need the
"offline_access" permission. I have code that does this in the SFC
Publish plugin part of Simple Facebook Connect. In your case you'll
also want the "create_event" permission.

2. When you do this and the user grants that permission, the resulting
login cookie that Facebook sets for that user will now have an
"expire" time of zero. This is your indicator that the Facebook
session key is a permanent one and that you need to save it and the
user value somewhere.  Again, SFC Publish has code that does this on
the Settings page, when the page is saved. You can also do it via AJAX
or something.

3. When you later need to make the request, you use the
set_user($user, $session_key) part of their PHP code. This sets up
your user without having to do all the other stuff, and anyway you
already know that you have a valid and working session key.

> 2)      I've been using wp_remote_post() to send the information to Facebook
> . but I'm not 100% sure I'm using the function correctly, and it's not very
> well documented in the source code.  The code I'm using is below . I've
> tried to copy the in-source examples of wp_remote_post(), but I know I could
> benefit from some additional guidance from those of you with more experience
> in cross-server communications.

Directly posting to Facebook's REST methods is a sucker's game. Do
yourself a favor and simply use their PHP libraries instead. This
tends to "just work" as opposed to rolling your own code.

Also, your example is wrong. You're posting to your application, not
to an API request. Bad way to go.

See here: http://wiki.developers.facebook.com/index.php/Events.create

> The Facebook application is meant to take this information and call the FB
> API directly (with the appropriate api and secret key).

Why not just make the plugin do it directly instead? Redirecting
through an app is pointless. Make the code do it directly with the
app's API key.


-Otto


More information about the wp-hackers mailing list