fql_query 返回“数组”而不是名字

发布于 2024-10-03 03:48:37 字数 465 浏览 0 评论 0原文

我正在尝试创建一个简单的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

怪我闹别瞎闹 2024-10-10 03:48:37

错误在于这一行:

echo "Name : $name[0][name]";

您在引号中包含 $name[0][name] ,这应该是

echo "Name : {$name[0][name]}";

    echo "Name : ".$name[0][name];

Mistake is in this line:

echo "Name : $name[0][name]";

you are including $name[0][name] in quotes, this should be

echo "Name : {$name[0][name]}";

or

    echo "Name : ".$name[0][name];
離殇 2024-10-10 03:48:37

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.

予囚 2024-10-10 03:48:37

每当我在 PHP 中使用数组或数据库/API 调用时,我都会使用 print_r($array_name) 来查看返回的内容。所以这个:

$name = $facebook->api_client->fql_query("SELECT name FROM user WHERE uid=$user_id");
print_r($name);

应该返回这个:

Array
(
    [0] => Array
    (
        [name] => First Last
    )
)

另一件事,我从来没有在 FQL 中的值/变量周围打勾。

$q = "SELECT name FROM user WHERE uid=$user_id";
$name = $facebook->api_client->fql_query($q);

但是,当您打印值时,您应该在对命名索引的引用(在本例中为“name”)两边加上单引号,并且不应将其全部用双引号引起来:

echo "Name : " . $name[0]['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:

$name = $facebook->api_client->fql_query("SELECT name FROM user WHERE uid=$user_id");
print_r($name);

Should return this:

Array
(
    [0] => Array
    (
        [name] => First Last
    )
)

Another thing, I never put tick marks around values/variables in FQL.

$q = "SELECT name FROM user WHERE uid=$user_id";
$name = $facebook->api_client->fql_query($q);

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:

echo "Name : " . $name[0]['name'];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文