Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a list of questions from stackoverflow API based on search query?

I am interested in the getting a list of the question based on a tag or a search query. I will give you an example.

So If I use the search keyword as "ipv4", it should give me a big list of questions related to ipv4. All I want to do is get the questions (title) as a list or an array so that I can do some processing on it.

like image 341
Vish Avatar asked Apr 03 '15 13:04

Vish


People also ask

How do I find questions to answer on stackoverflow?

Answering Questions. Go to https://stackoverflow.com/questions. You can use any web browser, like Chrome or Safari, to visit this site and answer questions. You can sort the questions by newest, active, bountied, unanswered, and more.

How many questions have been asked on stackoverflow?

As of March 2021 Stack Overflow has over 14 million registered users, and has received over 21 million questions and 31 million answers.

What is the most viewed question on stack overflow?

What's missing? Some observations: The top Stack Overflow question of all time — with more than 7 million views since its creation 9 years ago — is not even a programming question: “How do I undo the most recent commits in Git”.


2 Answers

Stackexchange offers https://api.stackexchange.com/docs/advanced-search endpoint.

So for example, get on https://api.stackexchange.com/search/advanced?site=stackoverflow.com&q=firebase would return you something like this:

enter image description here

This is simplest example but as you will find in the docs, there are numerous parameters based on which search can be performed. Some of them are:

  • accepted - true to return only questions with accepted answers, false to return only those without. Omit to elide constraint.
  • answers - the minimum number of answers returned questions must have.
  • body - text which must appear in returned questions' bodies.
  • tagged - a semicolon delimited list of tags, of which at least one will be present on all returned questions.
  • title - text which must appear in returned questions' titles.
  • user - the id of the user who must own the questions returned.
  • ...

Hope this helps!

Cheers!

like image 95
Teodor Hirs Avatar answered Sep 20 '22 21:09

Teodor Hirs


You can get this information utilizing the questions/ route. In this call, you will pass the tag(s) you are interested in to the tagged parameter (separated by a semicolon (;)).

To constrain questions returned to those with a set of tags, use the tagged parameter with a semi-colon delimited list of tags. This is an and constraint, passing tagged=c;java will return only those questions with both tags. As such, passing more than 5 tags will always return zero results.

For your specific question (searching for ipv4), you can utilize this as a starting point:

http://api.stackexchange.com/docs/questions#order=desc&sort=activity&tagged=ipv4&filter=!BHMIbze0EPheMk572h0ktETsgnphhU&site=stackoverflow&run=true

The filter is optional, but I've stripped out some of the default fields to present a smaller example. The link above returns entries that look like this:

"items": [
{
  "tags": [
    "ruby-on-rails",
    "ipv4",
    "geokit"
  ],
  "link": "http://stackoverflow.com/questions/29460004/rails-geokit-incorrectly-converting-ipv4-address-to-latitude-and-longitude",
  "title": "Rails: Geokit incorrectly converting IPv4 address to latitude and longitude"
},
{
  "tags": [
    "networking",
    "ip",
    "ipv4",
    "maxmind",
    "cidr"
  ],
  "link": "http://stackoverflow.com/questions/28358851/merging-of-multiple-ipv4-address-blocks-on-the-basis-of-their-country-region",
  "title": "merging of multiple IPv4 address blocks on the basis of their country region"
},
...
}
like image 33
Andy Avatar answered Sep 18 '22 21:09

Andy