2

I'm using Stackexchange java client lib I wanted to get a little more statistics but the following snippet returns only 30 answers.

  • Do I need to to register for an API key, or just use AnswersForUserRequestConfiguration?
  • How can I filter answers by a tag?

INFO: No API key provided, request limit will be restricted.

List<Answer> answers = StackAppClient.getAnswersForUser(241590);
    long votes=0;
    for ( Answer a : answers ) {
        votes += a.getUpVoteCount();
         System.err.println("answer:" + a);
    }
    System.err.println("votes:" + votes);

EDIT:

I think I shouldn't try to use getQuestionsForTag("java") which would return 50k+ answers and check whether I provided an answer to this question.

1 Answer 1

2

If you want that warning to go away you will need to get an API key. If you don't use a key your limited to something like 300 calls a day.

There isn't an easy way to get your answers by question tags. I would imagine the search feature might do something like that but at the moment it is limited and I haven't exposed it in the released version of the library. You can have up to 100 items in a response so the following will do what you are looking for although it will use (your answer count + your answer count / 100) API calls to do it and that could easily use your API quota up if you have answered a lot of questions:

List<Answer> answers = StackAppClient.getAnswersForUser(241590, AnswersForUserRequestConfiguration.start().withPageSize(100));
long votes = 0;
long totalAnswers = 0;
long javaAnswers = 0;
int page = 1;
while(answers.size() != 0 && answers.get(0).getAnswerId() != 0)
{
  for (Answer a : answers)
  {
    totalAnswers++;
    votes += a.getUpVoteCount();
    System.err.println("answer:" + a);
    Question question = StackAppClient.getQuestionById(a.getQuestionId());
    if(Arrays.asList(question.getTags()).contains("java"))
    {
      javaAnswers++;
    }
  }
  page++;
  answers = StackAppClient.getAnswersForUser(241590, AnswersForUserRequestConfiguration.start().withPageSize(100).withPage(page));
}
System.err.println("votes:" + votes);
System.err.println("java answers:" + javaAnswers);
System.err.println("total answers:" + totalAnswers);
2
  • @carsons thanks for your support, now it seems tha I'm supossed to store data I've already retrieved, in a local db for further use.
    – stacker
    Jun 6, 2010 at 17:25
  • Can the tags be added to the answers themselves? That will save a huge number of calls. Dec 1, 2010 at 16:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .