FQL Query from PHP using cURL returning “Method No

2019-09-01 05:46发布

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:

http://api.facebook.com/method/fql.query?query=SELECT 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 = 'http://api.facebook.com/method/fql.query?query=SELECT name FROM user WHERE uid=**********';
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $response = curl_exec($ch);
        curl_close($ch);
        echo($response);

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.

2条回答
贪生不怕死
2楼-- · 2019-09-01 06:24

I do not know much about the error messages associated with FQL but the SQL query is supposed to be url escaped (urlencode - http://php.net/manual/en/function.urlencode.php). Perhaps this could help your error.

查看更多
Melony?
3楼-- · 2019-09-01 06:40

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

$query = 'SELECT name FROM user WHERE uid=**********';
$url = 'http://api.facebook.com/method/fql.query?query=' . rawurlencode($query);

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

查看更多
登录 后发表回答