将graphEdge转换为数组

时间:2016-09-29 09:35:21

标签: php facebook facebook-php-sdk

我尝试将GraphEdge转换为数组 我试试这个功能

onMessageReceived()

但似乎很清楚一些数据或我不知道..使用此功能后反应的价值为空

这里是我的代码:

$response->getGraphEdge()->asArray();

结果如果我不使用asArray()

    $request = $this->facebook->request('GET', '/[ID_OF_MY_FAN_PAGE]/posts?fields=type,shares,reactions.limit(0).summary(true)&limit=5&since=1474473391');

    try {
      $response = $this->facebook->getClient()->sendRequest($request);
    } catch(Facebook\Exceptions\FacebookResponseException $e) {
      // When Graph returns an error
      echo 'Graph returned an error: ' . $e->getMessage();
      exit;
    } catch(Facebook\Exceptions\FacebookSDKException $e) {
      // When validation fails or other local issues
      echo 'Facebook SDK returned an error: ' . $e->getMessage();
      exit;
    }


    $posts = $response->getGraphEdge();
    $posts = $posts->asArray();

当我使用asArray()

时的结果
array(5) {
    [0]=>
    object(Facebook\GraphNodes\GraphNode)#14 (1) {
      ["items":protected]=>
      array(4) {
        ["type"]=>
        string(5) "photo"
        ["shares"]=>
        object(Facebook\GraphNodes\GraphNode)#12 (1) {
          ["items":protected]=>
          array(1) {
            ["count"]=>                <------- NB_SHARES
            int(707)
          }
        }
        ["id"]=>
        string(30) "252XXX6_10154318225934457"
        ["reactions"]=>
        object(Facebook\GraphNodes\GraphEdge)#13 (5) {
          ["request":protected]=>
          object(Facebook\FacebookRequest)#9 (9) {
            ["app":protected]=>
            object(Facebook\FacebookApp)#4 (2) {
              ["id":protected]=>
              string(15) "XXXX"
              ["secret":protected]=>
              string(32) "XXXX"
            }
            ["accessToken":protected]=>
            string(177) "xxxxxxx"
            ["method":protected]=>
            string(3) "GET"
            ["endpoint":protected]=>
            string(108) "/252XXX6/posts?fields=type%2Cshares%2Creactions.limit%280%29.summary%28true%29&limit=5&since=1474473391"
            ["headers":protected]=>
            array(1) {
              ["Content-Type"]=>
              string(33) "application/x-www-form-urlencoded"
            }
            ["params":protected]=>
            array(0) {
            }
            ["files":protected]=>
            array(0) {
            }
            ["eTag":protected]=>
            NULL
            ["graphVersion":protected]=>
            string(4) "v2.6"
          }
          ["metaData":protected]=>
          array(1) {
            ["summary"]=>
            array(2) {
              ["total_count"]=>   <------- NB_REACTIONS
              int(3892)
              ["viewer_reaction"]=>
              string(4) "NONE"
            }
          }
          ["parentEdgeEndpoint":protected]=>
          string(41) "/252XXX6_1XXXX7/reactions"
          ["subclassName":protected]=>
          NULL
          ["items":protected]=>
          array(0) {
          }
        }
      }
    }
    [1]=>
    object(Facebook\GraphNodes\GraphNode)#17 (1) {
      ["items":protected]=>
      array(4) {
        ["type"]=>
        string(4) "link"
        ["shares"]=>
        object(Facebook\GraphNodes\GraphNode)#15 (1) {
          ["items":protected]=>  
          array(1) {
            ["count"]=>      <------- NB_SHARES
            int(367)
          }
        }
        ["id"]=>
        string(30) "252XXX6_101XXXXX7"
        ["reactions"]=>
        object(Facebook\GraphNodes\GraphEdge)#16 (5) {
          ["request":protected]=>
          object(Facebook\FacebookRequest)#9 (9) {
            ["app":protected]=>
            object(Facebook\FacebookApp)#4 (2) {
              ["id":protected]=>
              string(15) "XXXX"
              ["secret":protected]=>
              string(32) "XXXX"
            }
            ["accessToken":protected]=>
            string(177) "XXXXX"
            ["method":protected]=>
            string(3) "GET"
            ["endpoint":protected]=>
            string(108) "/252XXXX/posts?fields=type%2Cshares%2Creactions.limit%280%29.summary%28true%29&limit=5&since=1474473391"
            ["headers":protected]=>
            array(1) {
              ["Content-Type"]=>
              string(33) "application/x-www-form-urlencoded"
            }
            ["params":protected]=>
            array(0) {
            }
            ["files":protected]=>
            array(0) {
            }
            ["eTag":protected]=>
            NULL
            ["graphVersion":protected]=>
            string(4) "v2.6"
          }
          ["metaData":protected]=>
          array(1) {
            ["summary"]=>
            array(2) {
              ["total_count"]=>  <------- NB_REACTIONS
              int(1466)
              ["viewer_reaction"]=>
              string(4) "NONE"
            }
          }
          ["parentEdgeEndpoint":protected]=>
          string(41) "/252XXX6_101XXXX7/reactions"
          ["subclassName":protected]=>
          NULL
          ["items":protected]=>
          array(0) {
          }
        }
      }
    }

是否还有其他解析getGraphEdge的解决方案?或Facebook的其他功能,以保持反应的价值?

0 个答案:

没有答案