egcmx Posted October 30, 2013 Report Posted October 30, 2013 (edited) so here is my code: <?php $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: 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 October 30, 2013 by egcmx
falkencreative Posted October 31, 2013 Report Posted October 31, 2013 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?
egcmx Posted October 31, 2013 Author Report Posted October 31, 2013 (edited) yes i'm following a tutorial. when i try to print $json_object or $fb_data it returns a null/blank value. Edited October 31, 2013 by egcmx
falkencreative Posted October 31, 2013 Report Posted October 31, 2013 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.
egcmx Posted November 3, 2013 Author Report Posted November 3, 2013 thanks again ben! you saved me for the second time!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now