PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, February 11, 2022

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

 February 11, 2022     facebook, facebook-graph-api, facebook-php-sdk, facebook-sdk-4.0, php     No comments   

Issue

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


Solution

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
)


Answered By - Seeker
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing