Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding Facebook Connect to a CodeIgniter website
    primarykey
    data
    text
    <p>I'm having problems trying to connect my website to Facebook. What I would like it to do is allow users to augment their accounts by connecting them to Facebook (I do not need people to be able to login with Facebook, I am using OpenID instead). My website runs in the CodeIgniter framework.</p> <p>What I will do is remove everything that I've tried and walk you through my steps up until it stops working.</p> <p><strong>Step 1: Set up the JavaScript SDK and XFBML</strong></p> <p>First I add a reference to the FBML spec to my <code>&lt;html&gt;</code> tag:</p> <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml" xml:lang="en" lang="en"&gt; </code></pre> <p>Then, after my <code>&lt;body&gt;</code> tag, I add:</p> <pre><code>&lt;script src="http://static.new.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript"&gt;&lt;/script&gt; </code></pre> <p>Now here comes the first problem I had <a href="https://stackoverflow.com/questions/3104455/why-is-my-facebook-connect-button-taking-me-to-the-wrong-url">but have now solved</a>. The problem was that the docs for the JavaScript SDK say that the <code>FB.init()</code> method <a href="http://developers.facebook.com/docs/reference/javascript/FB.init" rel="nofollow noreferrer">requires the appId</a> as a parameter, but this turned out to be incorrect. I needed to pass my apiKey instead. So this is the code that I ended up with, that goes before my <code>&lt;/body&gt;</code> tag:</p> <pre><code>&lt;div id="fb-root"&gt;&lt;/div&gt; &lt;script src="http://connect.facebook.net/en_US/all.js"&gt;&lt;/script&gt; &lt;script&gt; FB.init({ apiKey : '&lt;?php echo $this-&gt;config-&gt;item('facebook_api_key'); ?&gt;', status : true, cookie : true, xfbml : true }); &lt;/script&gt; </code></pre> <p>Now I can add XFBML entities to my pages, such as <code>&lt;fb:login-button&gt;&lt;/fb:login-button&gt;</code> which works just as expected. I click it and it pops up a box asking if I want to allow my website to access my Facebook profile. I say yes, and then if I check my Application Settings in Facebook, I can see that my website has been added.</p> <p>So this step works fine.</p> <p><strong>Step 2: Set up the PHP library</strong></p> <p>Okay, so now I need to add the PHP library. So a quick google search for 'codeigniter facebook library' reveals <a href="http://www.haughin.com/code/facebook/" rel="nofollow noreferrer">Elliot Haughin's library</a>. I download the files, put them all in the right places then get to work on loading the library.</p> <p>Now the current problem occurs. I add the following code (taken from the example given with the library) to my controller constructor so that it happens on every page:</p> <pre><code>$this-&gt;load-&gt;library('facebook_connect'); $this-&gt;data['fb_user'] = $this-&gt;facebook_connect-&gt;user; $this-&gt;data['fb_userid'] = $this-&gt;facebook_connect-&gt;user_id; </code></pre> <p>But if I do <code>print_r($this-&gt;data['fb_user']);</code> I get nothing. Ever. Whether I'm logged into facebook, logged out, logged in and added my site to my profile, etc. etc. etc. The user and user_id are never set. I don't get any errors though.</p> <p>As far as I'm aware, the values are supposed to be set so that I know whether the person browsing my site is logged into their facebook account. If they are, I can see if they've allowed my application. If they've allowed it, I can let them disconnect from my site, if not, I can let them connect. But I can't do anything if these variables aren't populated.</p> <p>I've tried poking around inside the source of the library, but I really can't get my head around it. And I'm hoping that the actual solution for this won't involve hacking the library apart. I'd expect a CodeIgniter specific library to work.</p> <p>Any ideas?</p> <p>Thanks a lot. :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload