如何访问Facebook SDK5返回数组?

时间:2016-08-01 08:52:15

标签: php facebook facebook-graph-api

我试过以下代码

try {
$response = $fb->get('/Daburindia?fields=about,name,username,emails,posts{likes{id,name,username}}', 'EAAD4AWyZB0kwBANvyxXW9TXMPrZANlxqrQhSuQVfy8SAl22dCyHI6ybWzbJj0vqTpOmTwdT6CRssZAjz8IdDQdtIyvGZC5ka4i7OAE1ttwwLhYzQOSDoKEy0SCC8FaJDipJOsGy34oubPCjzTTGl80ucQZDZD');
}
catch(Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;`}`
$user = $response->getGraphUser();
echo "<pre>";print_r($user);echo "</pre>";

此代码返回以下输出

Facebook\GraphNodes\GraphUser Object
(

[items:protected] => Array


(
        [about] => Dabur India Limited is the fourth largest FMCG Company in India with Revenue of over Rs 7,800 Crore & Market Capitalisation of over Rs 35,000 Cr.
        [name] => Dabur
        [username] => DaburIndia
        [emails] => Facebook\GraphNodes\GraphNode Object
            (
                [items:protected] => Array
                    (
                        [0] => corpcomm@dabur.com
                    )

            )

        [posts] => Facebook\GraphNodes\GraphEdge Object
            (
                [request:protected] => Facebook\FacebookRequest Object
                    (
                        [app:protected] => Facebook\FacebookApp Object
                            (
                                [id:protected] => 27268500XXXXX
                                [secret:protected] => dd5ea4b12338XXXXXXXXXXX
                            )

                        [accessToken:protected] => EAAD4AWyZB0kwBANvyxXW9TXMPrZANlxqrQhSuQVfy8SAl22dCyHbWzbJj0vqTpOmTwdT6CRssZAjz8IdDQdtIyvGZC5kazQOSDoKEy0SCC8FaJDipJOsGy34oubPCjzTTGl80ucQZDZD
                        [method:protected] => GET
                        [endpoint:protected] => /Daburindia?fields=about%2Cname%2Cusername%2Cemails%2Cposts%7Blikes%7Bid%2Cname%2Cusername%7D%7D
                        [headers:protected] => Array
                            (
                                [Content-Type] => application/x-www-form-urlencoded
                            )

                        [params:protected] => Array
                            (
                            )

                        [files:protected] => Array
                            (
                            )

                        [eTag:protected] => 
                        [graphVersion:protected] => v2.5
                    )

                [metaData:protected] => Array
                    (
                        [paging] => Array
                            (
                                [previous] => https://graph.facebook.com/v2.7/196011470503479/posts?fields=likes%7Bid,name,username%7D&since=1469764801&access_token=EAAD4AWyZB0kwBANvyxXW9TXMPrZANlxqrQhSuQVfy8SAl22dCyHI6ybWzbJj0vqTpOmTwdT6CRssZAjz8IdDQdtIyvGZC5ka4ioRCGdZBQOIkrLFSgDJ7OAE1ttwwLhYzQOSCC8FaJDipJOsGy34oubPCjzTTGl80ucQZDZD&limit=25&__paging_token=enc_AdAKFQ4lKXYaEZCP871Y20HcfFVxoLgpNnsai1cih4Akhye6jJ4zO2nmzoYYuZCtXiXnDpQGtLmxDJk9M4vas1EEoHGtzfZCVsUTvwZDZD&__previous=1
                                [next] => https://graph.facebook.com/v2.7/196011470503479/posts?fields=likes%7Bid,name,username%7D&access_token=EAAD4AWyZB0kwBANvyxXW9TXMPrZANlxqrQhSuQVfy8SAl22dCyHI6ybWzbJj0vqTpOmTwdT6CRssZAjz8ZC5ka4ioRCGdZBQOIkrLFSgDJ7OAE1ttwwLhYzQOSDoKEy0SCC8FaJDipJOsGy34oubPCjzTTGl80ucQZDZD&limit=25&until=1467087172&__paging_token=enc_AdBNrkEsyF7mHz0BRtycnrojGItDqifwODPZBlPzi29XZBngVJrZCm4RZBYEB8jgtQZB2votPR6Gv6LAIKRhxNvF2mg773EZBXiDjDPgWRpFcgZDZD
                            )

                    )

                [parentEdgeEndpoint:protected] => /196011470503479/posts
                [subclassName:protected] => 
                [items:protected] => Array
                    (
                        [0] => Facebook\GraphNodes\GraphNode Object
                            (
                                [items:protected] => Array

我正在尝试这个概念。我不知道索引[items:protected],[request:protected] =&gt; Facebook \ FacebookRequest对象,[app:protected],如何访问此阵列?我必须尝试访问索引,如$ user ['emails'] [0],但它有抛出错误作为未定义的索引

0 个答案:

没有答案