简体   繁体   English

访问stdClass对象中的数组元素

[英]Accessing array element inside stdClass object

I'm trying to access an element inside a Facebook API response. 我正在尝试访问Facebook API响应内的元素。 The response is a Facebook Graph Object which when outputted to the screen is shown below. 响应是一个Facebook图形对象,将其输出到屏幕时如下所示。

// 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. 我正在尝试访问数组中的“ unread_count”,但是没有运气。 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 资料来源: 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: 顺便说一句,请记住,您将不会获得具有Facebook客户端平台的read_mailbox批准:

This permission is granted to apps building a Facebook-branded client on platforms where Facebook is not already available. 此权限授予在尚不可用Facebook的平台上构建Facebook品牌客户端的应用程序。 For example, Android and iOS apps will not be approved for this permission. 例如,Android和iOS应用程序将不会获得此权限。 In addition, Web, Desktop and TV apps will not be granted this permission. 此外,不会向Web,桌面和电视应用授予此权限。

Source: https://developers.facebook.com/docs/facebook-login/permissions/v2.2 资料来源: https : //developers.facebook.com/docs/facebook-login/permissions/v2.2

You can try print_r(get_class_methods($object)). 您可以尝试使用print_r(get_class_methods($ object))。 This will return all methods associated with the object. 这将返回与该对象关联的所有方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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