fql_query 返回“数组”而不是名字
我正在尝试创建一个简单的 Facebook 应用程序,使用 fql_query 检索用户名。
代码:
require_once'facebook.php';
$appapikey = 'xxxx';
$appsecret = 'xxxx';
$facebook = 新 Facebook($appapikey, $appsecret) ;
$user_id = $facebook->require_login();
$q = "从用户中选择名称 WHERE uid='$user_id'";
$name = $facebook->api_client->fql_query($q);
echo "姓名: $name[0][name]";
输出: 名称:数组[名称]
你能告诉我这里出了什么问题吗? 谢谢!
I am trying to create a simple fb app that retrieves the name of the user using fql_query.
Code :
require_once 'facebook.php';
$appapikey = 'xxxx';
$appsecret = 'xxxx';
$facebook = new Facebook($appapikey, $appsecret) ;
$user_id = $facebook->require_login();
$q = "SELECT name FROM user WHERE uid='$user_id'";
$name = $facebook->api_client->fql_query($q);
echo "Name : $name[0][name]";
Output:
Name : Array[name]
Can you tell me what's going wrong here?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
错误在于这一行:
您在引号中包含 $name[0][name] ,这应该是
或
Mistake is in this line:
you are including $name[0][name] in quotes, this should be
or
FQL 查询始终返回一个数组,即使结果中只有一项也是如此。将结果视为普通 SQL 查询中的行。
An FQL query always returns an array, even if there is only one item in the result. Think of the result as rows in a normal SQL query.
每当我在 PHP 中使用数组或数据库/API 调用时,我都会使用 print_r($array_name) 来查看返回的内容。所以这个:
应该返回这个:
另一件事,我从来没有在 FQL 中的值/变量周围打勾。
但是,当您打印值时,您应该在对命名索引的引用(在本例中为“name”)两边加上单引号,并且不应将其全部用双引号引起来:
Any time that I use arrays or database/API calls in PHP I print_r($array_name) to see what was returned. So this:
Should return this:
Another thing, I never put tick marks around values/variables in FQL.
But when you print the value you should put single quotes around the reference to the named index (in this case, 'name') and you should not wrap it all in double quotes: