Small fixes to CodeIgniter, Facebook FQL via Graph with cURL (Phil Sturgeon’s library)

I went absolutely bonkers on trying to get CodeIgniter with Facebook Graph API via cURL.

Firstly, the problem here was the fact that everything was indeed working fine. Then when I tested my code again, things started breaking. Here’s my scenario.

I am using CodeIgniter 2.1.0 (the latest one) and I am trying to get the list of all the albums I have on Facebook via Facebook Graph API. In particular, I am running FQL to get these data, since I only need a few data fields.

In addition, I am also using Phil Sturgeon’s cURL library, so I don’t have to worry about all the nitty gritty details.

Here are TWO fixes I had to implement in my code to get things rolling.

  1. Specify “http_build_query” in Curl.php to handle ampersand character correctly.  According to the PHP site, this is what it states.

    As noted before, with php5.3 the separator is & on some servers it seems. Normally if posting to another php5.3 machine this will not be a problem. But if you post to a tomcat java server or something else the & might not be handled properly. To overcome this specify: http_build_query($array, ”, ‘&’).

    Looks like when interacting with Facebook Graph, you need to specify this.

  2. Specify options in cURL – Previously, I called a “simple_get( URL, array(‘q’ => my_fql, ‘access_token’ => my_access_token))”. When talking to FB, you need to specify the following options

    $this->curl->option(CURLOPT_SSL_VERIFYPEER, false);

    A little bit strange, since I didn’t have to do this before. But if Facebook is tweaking their systems all the time, which I imagine they do, we just need to adapt.

Hope that alleviates pain for some people who are doing similar things as me.

About Eric

ericbae.com - just a small place for me to jot down whatever I need to jot down. not much here. so don't get too disappointed. i won't.
This entry was posted in Coding, Question everything. Bookmark the permalink.

2 Responses to Small fixes to CodeIgniter, Facebook FQL via Graph with cURL (Phil Sturgeon’s library)

  1. Thanks for posting this!

    I’ve fixed the html_build_query() with that fix. It seems every other instance of the function was using the ‘&’ param but the one in Get, which is odd.

    Also you can just use $this->curl->ssl(false) as a shortcut. I wouldn’t use this on live, just on local as curl can get confused by SSL verification locally.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>