0

我質疑Facebook的用戶配置文件來訪問用戶語言裏GraphObject並獲得語言如何使用Facebook的PHP SDK V4

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 
       ) 

     ) 

) 

我想通過下面的代碼來訪問屬性如下回應Facebook\GraphObject,但無法獲得語言的數組:

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

print_r($languages); 

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

print_r($languages_array); 

有沒有其他辦法可以得到語言的信息

回答

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 
) 
相關問題