如何使用Facebook PHP SDK v4访问GraphObject中的用户语言

时间:2014-10-10 14:55:36

标签: php facebook facebook-graph-api facebook-php-sdk facebook-sdk-4.0

我查询了Facebook用户个人资料,并获得了语言

的以下回复Facebook\GraphObject
Facebook\GraphObject Object
(
    [backingData:protected] => Array
        (
            [0] => stdClass Object
                (
                    [id] => 106059522759137
                    [name] => English
                )

            [1] => stdClass Object
                (
                    [id] => 105673612800327
                    [name] => German
                )

            [2] => stdClass Object
                (
                    [id] => 106049856092338
                    [name] => Urdu
                )

        )

)

我试图通过以下代码访问该属性,但无法获取语言数组:

$languages = $Usergraph->getProperty("languages");
$languages_array = array();

print_r($languages);

foreach ($languages as $language){
    $languages_array[] = $language->getProperty('name');
}

print_r($languages_array);

有没有其他方法可以获得语言信息

1 个答案:

答案 0 :(得分:1)

好的我在找到可以投射我的GraphObject的信息后解决了该问题。所以解决方案将是这样的:

$languages = $Usergraph->getProperty("languages")->asArray();
$languages_array = array();
foreach ($languages as $language){
    $languages_array[] = $language->name;
}

print_r($languages_array);

将显示信息:

Array
(
    [0] => English
    [1] => German
    [2] => Urdu
)