使用 cURL 从 PHP 进行 FQL 查询返回“方法未实现”
一旦我知道用户的用户 ID,我就会使用 Facebook 的 Facebook 查询语言 (FQL) 来获取该用户的信息。当我在 Firefox 中输入以下 URL 时,它会返回请求的正确 XML:
http ://api.facebook.com/method/fql.query?query=SELECT name FROM user WHERE uid= **'
即返回用户的姓名。
注意:请不要建议使用 Graph API,因为实际上我将使用 FQL 来处理未在 Graph 中实现的事物,例如网络,这只是一个简单的示例。
但是,当我转到我的网站上执行以下 PHP 代码的页面时:
$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
这也不应该是身份验证问题,名称是公开可用的。
为了更深入地了解,当我输入任何格式错误的 FQL 请求时,PHP 页面会正确返回错误 XML,就像您在 Firefox 中输入 URL 时一样。只有当我输入正确形成的 FQL 请求时,它才与我在 Firefox 中看到的不同,即它给出了上面的错误,这甚至不是 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= **'
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否正确编码了查询参数?尝试如下操作:
或者您可以使用 Facebook PHP SDK 它会自动为您执行此操作。
Are you properly encoding the query parameters? Try something like:
Or you can use the Facebook PHP SDK which automatically does this for you.
我不太了解与 FQL 相关的错误消息,但 SQL 查询应该是 url 转义的 (urlencode - http://php.net/manual/en/function.urlencode.php)。也许这可以帮助您解决错误。
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.