Jump to content

Help With Facebook News Feed


Recommended Posts

so here is my code:



$page_id = '552721801408793';

$access_token = '558308744244333|TsDvTos1cL4WpQnWxQUdm0_xsTs';

//Get the JSON

$json_object = @file_get_contents('https://graph.facebook.com/' . $page_id .

'/posts?access_token=' . $access_token);

//Interpret data

$fbdata = json_decode($json_object);


foreach ($fbdata->data as $post)


$posts .= '<p><a href="' . $post->link . '">' . $post->story . '</a></p>';

$posts .= '<p><a href="' . $post->link . '">' . $post->message . '</a></p>';

$posts .= '<p>' . $post->description . '</p>';

$posts .= '<br />';




it gives me these errors: :bash:


Notice: Trying to get property of non-object in C:\xampp\htdocs\droga\feed.php on line 10


Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\droga\feed.php on line 10


please help me! thanks!

Edited by egcmx
Link to comment
Share on other sites

Have you tested the data at various stages in the code? For example, can you do a print_r() on the $json_object? If you don't have accurate access information, and if your URL is incorrect, you won't be able to display the information properly.


If that is fine, have you checked $fb_data? Does that hold the values you expect it to? Based on your error message, I doubt that $fb_data is an array, and it's likely you have an uncaught error in retrieving the data.


Are you following any specific tutorial for this functionality?

Link to comment
Share on other sites

I would start by looking at this line:


$json_object = @file_get_contents('https://graph.facebook.com/' . $page_id .

'/posts?access_token=' . $access_token);


and removing the "@" to enable error reporting for the line. My bet is that it's possible that due to the way your server is set up, you can't use file_get_contents() on an external URL. Removing the "@" and re-running the page should hopefully give you an error to work with.


If that is the case, see the "some notes" section of the tutorial (near the bottom). You'd need to go about retrieving this information in a different way -- likely through CURL rather than JSON.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...