A user has accepted my Facebook app. I can now access some of their data. It is returned as a graphObject
, which contains something like:
Facebook\GraphObject Object ( [backingData:protected] => Array ( [id] => 11111 [first_name] => Bob [gender] => male [last_name] => Builder [link] => https://www.facebook.com/app_scoped_user_id/11111/ [locale] => de_DE [name] => Bob Builder [timezone] => 2 [updated_time] => 2014-02-14T14:35:54+0000 [verified] => 1 ) )
Unfortunately I cannot get at the data inside this object. Reading it like an array throws an error:
$fbid = $graphObject['id']; // Cannot use object of type Facebook\GraphObject as array
$fbid = $graphObject->id; // Undefined property: Facebook\GraphObject::$id
Note that from API version >= 5.0.0
getProperty()
has been renamed togetField()
. It will be removed from >= v6. SoInstead of
Use
If you have casted the response as a GraphObject by using one of the following two methods:
You can use the
Get
properties of the graph object, depending on what kind of object you've casted it as... here's an example for theGraphUser
Object:Or, if you know the name of the property (as shown in the base data), you can use
getProperty()
:So in your example, you can use the following to get the
id
property:More examples and documentation here
In the New version of Graph API
getProperty
does not work. For the New version Graph API v2.5 of Facebook Read read data as below :