Tag Info

Hot answers tagged

9

I suspect your problem (as I commented) is XSS related. Try using JSONP instead of raw JSON; we just added support for the jsonp parameter.


8

As long as has_more is set to true there is more data available. You can get this data by increasing the page parameter in your request subsequently and running new request with that changed page parameter. The next url for your example would then be ...


7

As Kevin says, XSS. Try this instead: $.getJSON("http://api.stackoverflow.com/0.8/stats?jsonp=?", function(data){ alert(data.statistics[0]['total_questions']); });


5

Shot in the dark, but I bet "0.9" should be "1.0" in your code. The API version is currently 1.0, 0.9 was a beta version which has long since been deprecated.


5

While this would indeed be ideal for planned outages, your code and/or libraries & dependencies should be able to handle this elegantly, lest you get bitten by the unplanned outages.


3

Here is the relevant section of code from stack.PHP. $ch = curl_init(); curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_ENCODING,'gzip'); // Needed by API curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); $data = curl_exec($ch);


3

Sorry about that, I had completely forgot I disabled Gzip compression in Firefox due to a misbehaving site a few months ago. This does explain why some JSON preview apps show garbage instead of actual JSON: They don't handle Gzip compression.


2

I think your problem is that you're forgetting that the API only supplies gzipped data. I don't use Ruby, so you'll have to figure out how to tell curl to accept gzip data.


2

Not that this will solve you're main problem, but that actually isn't part of the API. If you go to api.stackexchange.com you kind information on how to get the data "raw", in JSON format. Sadly however the API doesn't let you get reputation changes for multiple days at once, so you're still stuck with making lots of GET requests. (I'm curious how you ...


2

Yes, UTF-8 is the guaranteed encoding, at least for versions 1.0 and 1.1. The others aren't nearly as popular, and waste a lot of space besides.


2

It is impossible to fetch all of Stack Overflow's users in a single API call, or even in a single day (using just the API and one IP address). There are currently 1,995,355 users on Stack Overflow. Which means that you would need 19,954 API calls to get them all, but your maximum API quota is 10,000 calls per day. The smart thing to do is to have your app ...


2

JSON is faster and more compact, so it is easier on the server, and easier to parse in most application languages -- while still being human-readable. Since the API is returning data, rather than markup, JSON is a much better choice than XML. If you insist on XML, there are a great   many   ways   to convert the data yourself, without loading the API ...


1

Thanks to Dave for this ;) Your for loop should be: var i, l; for (i = 0, l = data.items.length; i < l; i++) { // Get your data here }


1

Since OP has asked about fetching new questions, I can tell about that. /search works fine if you have two or three tags. But if you have a dozen, you'll get recent questions with delay of 5-15 minutes (as OP noted in the comments). Also, min/max parameters become terribly imprecise: you can get a post 10 minutes before min or miss post 10 minutes after it. ...


1

/search has atagged parameter with OR semantics. The # of returns is capped, and the results are very heavily cached. Things get tricky when somebody asks for everything tagged c# or java, and then the API is stuck trying to shove back 200k questions (optionally with answers and comments); thus the heavy constraints on OR'ing tags.


1

Try to set the Accepted-encoding like: curl = Curl::Easy.new(url_so) curl.headers["Accept-Encoding"] = "gzip,deflate" curl.perform


1

gzuncompress is for ZLIB not GZIP. The two algorithms are related, but not identical. gzuncompress isn't strictly guaranteed to decompress all ZLIB streams actually, its just guaranteed to decode the results of gzcompress. Which is honestly really weird. The appropriate function is gzdecode. If that's not available, http_inflate should also work.



Only top voted, non community-wiki answers of a minimum length are eligible