Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialShelby Larson
33,317 PointsGetting and Storing JSON Code Challenge task 5
The question: Create a variable named my_plugin_profile. Assign it the JSON decoded value of the json_feed array's body index. Then return the my_plugin_profile variable.
My code: <?php
function my_plugin_get_profile($my_plugin_username) { $json_feed_url = 'http://myapi.net/' . $my_plugin_username . '.json'; $args = array('timeout' => 120); $json_feed = wp_remote_get( $json_feed_url, $args ); $wptreehouse_profile = json_decode( $json_feed['$my_plugin_profile'] ); return $json_feed['$my_plugin_profile']; }
?>
I don't understand what I'm doing wrong.
2 Answers
Jill Sheeks
11,169 PointsThis is what I used and it worked. <?php
function my_plugin_get_profile($my_plugin_username) { $json_feed_url = 'http://myapi.net/' . $my_plugin_username . '.json'; $args = array('timeout' => 120); $json_feed = wp_remote_get( $json_feed_url, $args ); $my_plugin_profile = json_decode( $json_feed['body'] ); return $my_plugin_profile; }
?>
Kenan Memis
47,314 PointsHi, The final part of your answer, the return statement, just replace it with the following:
return $my_plugin_profile;
matsum0t0
12,520 Pointsmatsum0t0
12,520 PointsHey there, I'm going to attempt to help you without giving you the answer. First "Create a variable named $my_plugin_profile." (not $wptreehouse_profile). Second "Assign it the JSON decoded value of the json_feed array's 'body' index" so your array[] needs a different value, extracted from the $json_feed. Lastly "Then return the my_plugin_profile variable." The $json_feed was already assigned to the $my_plugin_profile so you just need to return the my_plugin_profile variable. That may get you a little further, or you could be completely finished already. oh well.
M@