java - How to adjust the number of results returned when querying the Stackoverflow API? -


i'm using stackoverflow json api retrieve questions marked given tag.

i have small program in java retrieves questions marked "java" tag.

public static void main(string[] args) throws exception {     string urlstring = "https://api.stackexchange.com/2.1/questions?order=desc&sort=votes&tagged=java&site=stackoverflow";      url url = new url( urlstring );      bufferedreader reader = null;      stringbuffer buffer = new stringbuffer();     try     {         urlconnection connection = url.openconnection();          inputstream isconn = connection.getinputstream();          reader = new bufferedreader( new inputstreamreader( new gzipinputstream( isconn ) ) );          string inputline;          while (( inputline = reader.readline() ) != null)         {             buffer.append( inputline );         }     }         {         if (reader != null)         {             reader.close();         }     }      jsonobject jsonobject = new jsonobject( buffer.tostring() );      jsonarray jsonarray = jsonobject.getjsonarray( "items" );      system.out.println( buffer );     system.out.println( jsonarray.length() ); } 

my problem returns 30 questions. since goal build dataset further textual analysis, need access way more 30 questions.

is there way adjust size of returned list?

if not, how can workaround situation?

notice has_more property in returned json, indicates more results available. can page through these results using page , pagesize parameters in url. issue foresee code pulling large number of questions considering iterate through java questions, may want add conditional stops @ number of pages. here quick example:

public static void main(string[] args) throws exception {      bufferedreader reader = null;     int page = 1;     jsonobject jsonobject = null;     try {         while (jsonobject == null || jsonobject.getboolean("has_more")) {             string urlstring = "https://api.stackexchange.com/2.1/questions?order=desc&sort=votes&tagged=java&site=stackoverflow&pagesize=100";             urlstring += "&page=" + page++;             url url = new url(urlstring);             urlconnection connection = url.openconnection();              inputstream isconn = connection.getinputstream();             stringbuffer buffer = new stringbuffer();             reader = new bufferedreader(new inputstreamreader(new gzipinputstream(isconn)));              string inputline;              while ((inputline = reader.readline()) != null) {                 buffer.append(inputline);             }              jsonobject = new jsonobject(buffer.tostring());             jsonarray jsonarray = jsonobject.getjsonarray("items");              system.out.println(buffer);             system.out.println(jsonarray.length());         }     } {         if (reader != null) {             reader.close();         }     }  } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -