简体   繁体   中英

Accessing array element inside stdClass object

I'm trying to access an element inside a Facebook API response. The response is a Facebook Graph Object which when outputted to the screen is shown below.

// send request
$response = (new FacebookRequest($session, 'GET', '/me/inbox?limit=0'))->execute();

// get Facebook Graph Object
$object = $response->getGraphObject();

echo print_r($object);

//Output from print_r
Facebook\GraphObject Object ( 
    [backingData:protected] => Array ( 
        [data] => Array ( ) [summary] => stdClass Object ( 
             [unseen_count] => 0 [unread_count] => 6 [updated_time] => 2014-11-09T13:41:26+0000 ) 
    ) 
) 

I'm trying to access 'unread_count' inside the array however having no luck. Could someone also explain what it is as its not your typical array and includes objects.

Try this:

$object = $response->getGraphObject()->asArray();
echo var_dump($object);

Source: https://developers.facebook.com/docs/php/GraphObject/4.0.0


Btw, keep in mind that you will not get read_mailbox approved for platforms with a Facebook client:

This permission is granted to apps building a Facebook-branded client on platforms where Facebook is not already available. For example, Android and iOS apps will not be approved for this permission. In addition, Web, Desktop and TV apps will not be granted this permission.

Source: https://developers.facebook.com/docs/facebook-login/permissions/v2.2

You can try print_r(get_class_methods($object)). This will return all methods associated with the object.

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