简体   繁体   中英

How to access user languages inside GraphObject using Facebook PHP SDK v4

I queried the Facebook User Profile and get the Following response Facebook\\GraphObject for Languages

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
                )

        )

)

I am trying to access the property by following code but unable to get the array of languages:

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

print_r($languages);

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

print_r($languages_array);

Is there any other way i can get the information of language

Ok i Resolved that Issue after finding the information that i can cast my GraphObject as well. So solution will be like this:

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

print_r($languages_array);

and the Information will be displayed:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM