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 trial

WordPress

charlesporter
charlesporter
3,308 Points

I am taking the JSON portion of the wordpress plugin course and I am getting this message: string(9) "Not found"

It appears everything is working OK except the function below:

<?php
function cp_get_profile( $cp_username ) {

    $json_feed_url = 'http://teamtreehouse.com/' . $cp_username . '.json';
    $args = array( 'timeout' => 120 );

    $json_feed = wp_remote_get( $json_feed_url, $args );

    return $json_feed['body'];
}

When I go into the database and look at the Browse I see this:

a:3:{s:15:"cp_username";s:13:"charlesporter";s:14:"cp_profile";s:9:"Not found";s:11:"last_upated";i:1422793097;}

ALSO,

I added this echo statement echo $json_feed_url; just before the return $json_feed and this is what was displayed on the screen:

http://teamtreehouse.com/charlesporter.json

string(9) "Not found"

My variable $json_feed_url is correct so why the error?

5 Answers

Brainwave!

I just happened to notice that your username isn't a link to your profile page here on the forums - mine is. This says to me that your privacy settings are maybe preventing the viewing of your profile url, and ultimately your .json feed.

Try going to your Account Settings > Privacy Settings and checking the 'Allow everyone to see your profile' option, then try it again.

Good luck! :-)

If you look in the array that's being stored within the options data you will see that the 'body' is actually returning an error that is being stored in your options. This said to me that the username was possibly invalid. So I went and had a look for the profile at http://teamtreehouse.com/charlesporter - which doesn't exist.

When the wp_remote_get() is heading off for the info it get's a not found error from the Treehouse API and stores that in the database, which you are then displaying.

Double check you have a valid Treehouse username stored and you should be in business as the rest of your code looks fine. :-)

charlesporter
charlesporter
3,308 Points

I looked under my account setting and this is what shows up:

Treehouse Profile URL teamtreehouse.com/charlesporter

charlesporter
charlesporter
3,308 Points

That did the trick. Thanks much!!

Glad I could help, and that you got it working in the end!