I'm trying to integrate Facebook API into Wordpress. It seems I can't include the API when I edit the pages directly in PHP:
$facebook = new Facebook(array(
'appId' => '?',
'secret' => '?',
'cookie' => true,
));
$session = $facebook->getSession();
Always returns a blank session unless I put the code in the wp-blog-header.php or index.php for the Wordpress install itself. I believe this is because it's trying to set cookies and can't at this point. Does anyone know how I can get this to work? I really don't want to have to create some stupid work around.
This should help. It is a full article from SmashingMag on how to do just that.
http://www.smashingmagazine.com/2009/09/14/how-to-integrate-facebook-with-wordpress/
I think you have to have a canvas to link to. This article will show you both adding you blog posts to facebook and adding facebook to your blog.
I'm not entirely sure that it's because cookies haven't been loaded yet. But try this:
Add the following to your theme's functions.php
file (the 'init' action should make this get called long after cookies and such have loaded):
<?php
function facebook_setup() {
global $facebook;
$facebook = new Facebook(array(
'appId' => '?',
'secret' => '?',
'cookie' => true,
));
}
add_action('init', 'facebook_setup');
?>
And then calling that global variable in your templates. e.g.
<?php
global $facebook;
$me = $facebook->api('/me');
print_r($me);
?>
I'm not sure if this will fix the issue. Depending on how you setup Facebook's Oauth flow, there might be another cause to your problem.