Take the 2-minute tour ×
Stack Apps is a question and answer site for apps, scripts, and development with the Stack Exchange API. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

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);
share|improve this answer
    
@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 '10 at 17:25
    
Can the tags be added to the answers themselves? That will save a huge number of calls. –  Abhinav Sarkar Dec 1 '10 at 16:50
add comment

You must log in to answer this question.

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