-1

Why is that JSON feed returning an undefined variables while working for other variable? What am I doing wrong or overlooking? Thanks.

8
  • Difficult to say as provided link will return an error (Invalid parameter value: callback=?). If I remove the callback parameter from the url, the answer to your question is obvious, but I don't know if the data is valid. Commented Jan 6, 2010 at 7:34
  • @ybo, remove callback=? from link when rendering in browser and it return data as normal. callback=? is need to parse data with $.getJSON. Removing callback=? from URL does not return anything when using $.getJSON. Commented Jan 6, 2010 at 7:39
  • JSON structure is fine, but the item['media$group']['media$content'][0]['url'] and tem['yt$statistics']['viewCount'] don't exist in the returned data. Are you sure that user account is correct and is active? Commented Jan 6, 2010 at 8:01
  • @k prime, you seem right, the account holder must have removed their favorites because I had copied the returned json data from earlier and was just now starting to assign the var and parsing it. Now testing with another account just to make sure it work. Commented Jan 6, 2010 at 8:14
  • Now using this URL: gdata.youtube.com/feeds/users/soccerdude1935/… (account is active and it is returning all data) and I still error message when assigning var to item['media$group']['media$content'][0]['url'], item['media$group']['media$thumbnail'][0]['url'], and item['media$group']['media$content'][0]['duration'] even though they are present in the returned data. Commented Jan 6, 2010 at 8:21

1 Answer 1

1

If you take a look at the contents in response:

curl http://gdata.youtube.com/feeds/users/kaycor/favorites?alt=json-in-script&callback=mycallback

You see that entry.media$group and entry.yt$statistics are not there:

gdata.io.handleScriptLoaded({
    "feed": {
        // snip ...
        "entry": [{
            // snip ...
            "media$group": {
                "media$category": [{
                    // snip ...
                }],
                "media$title": {
                    // snip ...
                }
            }
        }]
    }
});

Edit: Not all items contain the media$content array, so you should modify your each block to something like this:

$.each(data.feed.entry, function(i, item){
    var uploader = item['author'][0]['name']['$t'];
    if (item['media$group']['media$content']) {
        var URL = item['media$group']['media$content'][0]['url'];
        var thum = item['media$group']['media$thumbnail'][0]['url'];
    }
});

I wrote a quick test script for this and with the if clause in place, it did not throw errors anymore.

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

2 Comments

@Priit, thanks for your reply. You're right, I just notice that the returned data from the account I was using is no longer returning those data since I retrieved the data earlier and was just now assigning variables. Updated my post. Still getting an error when assigning var to returned data.
@Priit, thanks a lot for your continuous help. Vote up for you sir. Almost there (thumb var does not work for some reason even with an if statement). See my latest update above and let me know if you have any suggestions.

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.