问题
I am writing an Open Data Table to aggregate like counts from various social networking services.
My attempt can be found here at the YQL console, with the Open Data Table XML being here.
My current problem - as you will find out on trying my query - is that Twitter and Facebook's requests return an empty response object with:
org.mozilla.javascript.UniqueTag@399a063e: NOT_FOUND
instead of populating it with the JSON that each respective service returns.
I think that the non-zero content-length header returned in the rest object indicates that the YQL server has received the correct JSON reply, and thus the problem isn't on the web services' sides but on either YQL's or my ODT's side.
I have tried to solve this problem in various ways and have been unsuccessful. Could some YQL experts please help me out?
Thank you.
回答1:
I have found my solution and this may be a bug in the YQL server.
What happens is that when a web service returns content with content-type 'application/json', YQL parses it into the E4X format, an xml representation for JavaScript. Why it does so, I do not have any clue on since JSON should be parsed into a JavaScript object.
The problem with this E4X format seems to be that it is only accessible within the optional callback function that can be supplied when calling y.rest().
When trying to store bits of data into a variable, and apply it to the response.object object, I found that the console would return a NOT FOUND error. This means that what I thought I had stored into my variables was not a string or integer value for these social button counts, but a reference to an E4X node.
To solve this problem, I performed parseInt magic on the node to get my numbers.
I believe this behaviour is very odd and is most likely an unintended bug. Hopefully, a developer will pick up on this issue to prevent future confusions.
来源:https://stackoverflow.com/questions/9706643/yql-odt-rest-get-response-exists-but-inaccessible