Viewed   72 times

I am using Facebook's Facebook Query Language (FQL) to get information on a user once I already know his user id. When I enter the following URL into Firefox, it returns the correct XML for the request: name FROM user WHERE uid= **'

Namely it returns the user's name.

Note: please don't suggest using Graph API as I will in fact be using FQL for things not implemented in Graph yet like networks, this is just a simple example.

BUT, when I go to the page on my website which executes the following PHP code:

        $url = ' name FROM user WHERE uid=**********';
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $response = curl_exec($ch);

I see:

 Method Not Implemented

 Invalid method in request

This shouldn't be an authentication problem either, name is something that is publicly available.

For more insight, when I enter any malformed FQL request, the PHP page correctly returns an error XML, just as it would when you enter the URL in Firefox. It is only when I enter a CORRECTLY FORMED FQL request that it differs from what I see in Firefox, namely, it gives the error above, which is not even XML.

Any ideas? Thanks.



Are you properly encoding the query parameters? Try something like:

$query = 'SELECT name FROM user WHERE uid=**********';
$url = '' . rawurlencode($query);

Or you can use the Facebook PHP SDK which automatically does this for you.

Friday, December 9, 2022

Post json objectusing curl.

$data = array('value1' => $value1, 'value2' => $value2);                                                                    
$data_string = json_encode($data);                                                                                   

$ch = curl_init('http://api.local/rest/users');   // where to post                                                                   
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);                                                                  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
    'Content-Type: application/json',                                                                                
    'Content-Length: ' . strlen($data_string))                                                                       

$result = curl_exec($ch);
Saturday, November 19, 2022

To get event attendees you can run following FQL query:

SELECT uid FROM event_member WHERE eid = "EXISTING_EVENT_ID"

Event id is something you can get from many sources, if you create event via Graph API you'll get event id as response. Or you can get ids of events current/specific user attending. Or as you already noted from URL of event page.

Next FQL query will return all events current user is attending:

SELECT eid FROM event_member WHERE uid = me() AND rsvp_status = "attending"

Queries can be nested so you can do stuff like get list of all attendees of all events current user ever attended:

SELECT eid, uid FROM event_member WHERE eid IN (
  SELECT eid FROM event_member WHERE uid = me() AND rsvp_status = "attending"

To get details of attendees for specific event something like this may do the work:

SELECT uid, name, pic_square FROM user WHERE uid IN (
  SELECT uid FROM event_member WHERE eid = "EXISTING_EVENT_ID"


  • You'll need any valid access_token to get public events details.
  • To retrieve events of current user you'll need user_events permission to be granted to your application by this user.
  • You can display user image with only knowing his id with URL in format of{USER_ID}/picture
  • You can run FQL queries with Graph API by issuing GET request to{QUERY_HERE}

For more details on FQL and Graph API read documentation, especially on tables event_member and user

Monday, October 17, 2022

The results from Facebook are in UTF-8 encoding.

ò character is c3b2 in UTF-8 (hex) 0xC3 - Ã 0xB2 - ²

To convert the results to ISO-8859-1 from UTF-8 in PHP you may use utf8_decode function:

$source = chr(0xc3).chr(0xb2);
$result = utf8_decode($source); // -> 0xF2 (ò in ISO-8859-1)
Tuesday, August 23, 2022
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);

should actually be:

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

so curl knows that it should return the data and not echo it out.

Additionally, sometimes you have to do some more work to get SSL certs accepted by curl:
Using cURL in PHP to access HTTPS (SSL/TLS) protected sites


Given your usage, you should also set CURLOPT_HEADER to false as Alix Axel recommended.

In terms of SSL, I hope you'll take time to read the link I suggested, as there are a few different ways to handle SSL, and the fix Alix recommended may be OK if the data isn't sensitive, but does negate the security, as it forces CURL to accept ANY SERVER CERTS.

Thursday, August 4, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :