2

I have convert my object data to an array and now i am trying to extract certain parts from the multi dimensional array however i am having some problems. Assistance is appreciated, thank you.

 /* PHP SDK v4.0.0 */
/* make the API call */
$request = new FacebookRequest(
  $session,
  'GET',
  '/89647580016/feed'
);
$response = $request->execute();
$graphObject = $response->getGraphObject()->AsArray();
/* handle the result */

  // print data

 echo '<pre>' . print_r( $graphObject, 1 ) . '</pre>';

The following is the output:

Array
(
    [data] => Array
        (
            [0] => stdClass Object
                (
                    [id] => 89647580016_10153019927930017
                    [from] => stdClass Object
                        (
                            [name] => Central Casting Los Angeles
                            [category] => Local Business
                            [category_list] => Array
                                (
                                    [0] => stdClass Object
                                        (
                                            [id] => 176831012360626
                                            [name] => Professional Services
                                        )

                                )

                            [id] => 89647580016
                        )

                    [message] => ***NON Union Submissions***
Must be registered with Central Casting!

Jessica is currently booking a TV show working tomorrow Friday June 26th with a possible recall Monday June 29th in LA. These will be Night Calls, so you must be okay working late into the night.
She is looking for Caucasian looking men, who appear to be in their 30's-50's, who appear to be very upscale, who have business suits.

If this is you please call submission line 818-260-3952. Thank you!
                    [actions] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [name] => Comment
                                    [link] => https://www.facebook.com/89647580016/posts/10153019927930017
                                )

                            [1] => stdClass Object
                                (
                                    [name] => Like
                                    [link] => https://www.facebook.com/89647580016/posts/10153019927930017
                                )

                            [2] => stdClass Object
                                (
                                    [name] => Share
                                    [link] => https://www.facebook.com/89647580016/posts/10153019927930017
                                )

                        )

How can i print all the ['message'] ? I tried:

foreach ($graphObject as $key => $value) {
 echo '<br>'.$key['message'];
}

But i got a error. Thank you for your help.

1 Answer 1

1

Your array has some keys which elements are actually StdClass. You can't reffer to it as $key['message'] but as: $key->message.

Also, don't forget to include your error message. An error is extremely generic and we can't/won't help you if there is no indication of what is wrong.

I didn't notice your foreach. As you are iterating only on $graphObject first level, you will get as $key data and as value another whole array which each key has a StdClass. On your foreach, run it as foreach ($graphObject['data'] as $key => $value) , then use it as echo $value->message

Sign up to request clarification or add additional context in comments.

3 Comments

I tried your solution and i didnt get anything returned. Also there was no error message, just a blank page. When I tried echo '<br>'.$key; it printed the word data.
i got a error: Warning: Invalid argument supplied for foreach()
Yeah, I realized that after posting it. It is an array. Quote data and wrap it with brackets and everything should be ok. I updated my answer once again to make it clear.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.