使用cURL返回的来自PHP的FQL查询“未实现方法” [英] FQL Query from PHP using cURL returning "Method Not Implemented"

查看:236
本文介绍了使用cURL返回的来自PHP的FQL查询“未实现方法”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一旦我已经知道他的用户ID,我使用Facebook的Facebook查询语言(FQL)来获取用户的信息。当我在Firefox中输入以下URL时,它会为请求返回正确的XML:

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 = * * '

http://api.facebook.com/method/fql.query?query=SELECT name FROM user WHERE uid= **'

也就是返回用户名。

注意:请不要使用Graph API,因为我实际上会使用FQL来在Graph中实现网络,而这只是一个简单的例子。

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.

但是,当我访问我的网站上执行以下PHP代码的页面时:

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);

我看到:

 Method Not Implemented

 Invalid method in request

这不应该是一个身份验证问题,名称是公开的东西。

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

为了进一步了解,当我输入任何格式不正确的FQL请求时,PHP页面会正确返回错误XML,就像在Firefox中输入URL一样。只有当我输入一个CORRECTLY FORMED FQL请求,它不同于我在Firefox中看到的,即,它给出了上面的错误,甚至不是XML。

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 = 'http://api.facebook.com/method/fql.query?query=' . rawurlencode($query);

或者您可以使用 Facebook PHP SDK ,它会自动为您执行此操作。

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

这篇关于使用cURL返回的来自PHP的FQL查询“未实现方法”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆