Is there a way to get a list or json of all the subreddits using the api? - reddit

I've been looking at the API methods and couldn't find one that would return a json with all the subreddits. Or is the only way to do this is by scraping reddit.com/reddits?

Add .json to the end of the URL: http://www.reddit.com/reddits.json

Related

On a swagger-UI page, can I default the json to explore with a query string parameter?

I have a swagger-ui/index.html I would like to be able to publish URLs to various APIs using the same html. Is here a way to pass in the json to be explored via a query string parameter?
Yes, this can be done by passing in the json path using ../swagger-ui/?url=http://something.com/swagger.json

Parsing twitter json response

I've made a twitter api request (GET trends/place API) and the result is just like this:
[{"trends":[{"name":"#BabyIsStaying","url":"http:\/\/twitter.com\/search?q=%23BabyIsStaying","promoted_content":null,"query":"%23BabyIsStaying","events":null},{"name":"#AkTakipBa\u015fl\u0131yor","url":"http:\/\/twitter.com\/search?q=%23AkTakipBa%C5%9Fl%C4%B1yor","promoted_content":null,"query":"%23AkTakipBa%C5%9Fl%C4%B1yor","events":null},{"name":"#\u00c7apulcuTakip","url":"http:\/\/twitter.com\/search?q=%23%C3%87apulcuTakip","promoted_content":null,"query":"%23%C3%87apulcuTakip","events":null},{"name":"#SadeceKar\u015f\u0131l\u0131kl\u0131Takiple\u015fme","url":"http:\/\/twitter.com\/search?q=%23SadeceKar%C5%9F%C4%B1l%C4%B1kl%C4%B1Takiple%C5%9Fme","promoted_content":null,"query":"%23SadeceKar%C5%9F%C4%B1l%C4%B1kl%C4%B1Takiple%C5%9Fme","events":null},{"name":"#soysuzek\u015fis\u00f6zl\u00fck","url":"http:\/\/twitter.com\/search?q=%23soysuzek%C5%9Fis%C3%B6zl%C3%BCk","promoted_content":null,"query":"%23soysuzek%C5%9Fis%C3%B6zl%C3%BCk","events":null},{"name":"B\u00fcy\u00fck FENERBAH\u00c7E Taraftarlar\u0131Takiple\u015fiyor","url":"http:\/\/twitter.com\/search?q=%22B%C3%BCy%C3%BCk+FENERBAH%C3%87E+Taraftarlar%C4%B1Takiple%C5%9Fiyor%22","promoted_content":null,"query":"%22B%C3%BCy%C3%BCk+FENERBAH%C3%87E+Taraftarlar%C4%B1Takiple%C5%9Fiyor%22","events":null},{"name":"Sar\u0131K\u0131rm\u0131z\u0131Aile UnfollowsuzTakiple\u015fiyor","url":"http:\/\/twitter.com\/search?q=%22Sar%C4%B1K%C4%B1rm%C4%B1z%C4%B1Aile+UnfollowsuzTakiple%C5%9Fiyor%22","promoted_content":null,"query":"%22Sar%C4%B1K%C4%B1rm%C4%B1z%C4%B1Aile+UnfollowsuzTakiple%C5%9Fiyor%22","events":null},{"name":"D\u00fcnyadaTeksinSen GALATASARAY\u0131m","url":"http:\/\/twitter.com\/search?q=%22D%C3%BCnyadaTeksinSen+GALATASARAY%C4%B1m%22","promoted_content":null,"query":"%22D%C3%BCnyadaTeksinSen+GALATASARAY%C4%B1m%22","events":null},{"name":"D\u00fcnyan\u0131n TekHarikas\u0131s\u0131n FENERBAH\u00c7EM","url":"http:\/\/twitter.com\/search?q=%22D%C3%BCnyan%C4%B1n+TekHarikas%C4%B1s%C4%B1n+FENERBAH%C3%87EM%22","promoted_content":null,"query":"%22D%C3%BCnyan%C4%B1n+TekHarikas%C4%B1s%C4%B1n+FENERBAH%C3%87EM%22","events":null},{"name":"MustafaKemalin\u0130zindeyiz \u00c7\u00fcnk\u00fcFenerbah\u00e7eliyiz","url":"http:\/\/twitter.com\/search?q=%22MustafaKemalin%C4%B0zindeyiz+%C3%87%C3%BCnk%C3%BCFenerbah%C3%A7eliyiz%22","promoted_content":null,"query":"%22MustafaKemalin%C4%B0zindeyiz+%C3%87%C3%BCnk%C3%BCFenerbah%C3%A7eliyiz%22","events":null}],"as_of":"2013-07-20T10:51:45Z","created_at":"2013-07-20T10:45:24Z","locations":[{"name":"Turkey","woeid":23424969}]}]
My question is how to turn this array string into html. No proper php experience at all.
The response you are getting is JSON.
You used to be able to get response in XML, RSS and more, but now the only response type you will receive is JSON.
PHP has multiple methods for dealing with JSON. To encode data, you would use json_encode(). However, you want to decode it, so you want to be doing the following:
var_dump(json_decode($yourData));
This will dump the data to the browser so you can see what you have to work with.
You can iterate around this data using a foreach() loop.
Remember, assuming you json_decode() your results into $yourData:
To access array properties, use: $yourData['propertyName']
To access object properties, use: $yourData->propertyName
you can feed that into json_decode() function
you will get an array that you can manage as you want.

Extracting JSON data from node?

With a request to Twitter for example:
https://api.twitter.com/1/users/show.json?screen_name=stephenfry&include_entities=true
I can extract an element like followers_count using result["followers_count"]
I've tried a similar request to LastFM but their JSON is structured differently as it's a translation of their default XML.
With their demo request:
http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=Cher&api_key=b25b959554ed76058ac220b7b2e0a026&format=json
How would I get the listeners value?
I've tried
result["listeners"]
result["artist.listeners"]
result["artist.stats.listeners"]
I understand I need to access a node, but have no idea how to go about it.
Can anyone help?
It's a nested hash, so you can reach it with:
result["artist"]["stats"]["listeners"]
Example:
require('open-uri')
require('json')
result = JSON.parse(open('http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=Cher&api_key=b25b959554ed76058ac220b7b2e0a026&format=json').read)
result["artist"]["stats"]["listeners"].to_i
The Last.fm data is a series of nested hashes, so you need to access them as such. Give the following a try, it should do the trick:
result["artist"]["listeners"]

URL length limit for google reader api

I am using "/reader/api/0/stream/items/ids" API to get the item ids for sources that I want.
I have quite a number of sources, so I repeated "s=" parameter to include in the api url.
However, google has given me an error of "URL is too long".
So the question is that How can I solve it so that I just use one time api call to get item ids for that many sources?
Thanks
It seems that /reader/api/0/stream/items/ids path supports a POST method. This means the amount of data you could pass by using POST verb is much more than by using a query string and a GET method.
So use https://www.google.com/reader/api/0/stream/items/ids URL for the post, and pass your query string as a post data. Don't forget to include an action token(T) which is required for POST requests.

Parsing Bing News Search API Results

Hey i am trying to parse Bing News API Search results, using Regex but finding it real hard. Can any one tell how to extract - 1. Snippet, 2. URL and 3. Name from all the results(10 is the default number) that are returned in one response ?
This is the response that i am receiving from Bing for a query.(there are 5 results returned in this)
http://ideone.com/yd8yl
You don't need to use a regular expression for parsing the Bing response. The response is in JSON (JavaScript Object Notation) format, and depending on your programming environment, you may use an appropriate library to parse it. Please check http://www.json.org/ if you are not familiar with what JSON is.

Resources