3

I am using Javascript SDK of stackexchange API to get the data. First, i am logging in using the SDK and in return I am getting a JSON reponse about the details of the logged user of which, the user_id and token are of my use. Now, using the user_id or token, how can I fetch the count of questions, answers, reputation, badges and people reached of the user?

I will store the user_id and token in my database so that, whenever the user logins to my system, I will have to fetch the data i.e. reputation, badge count etc and show that in a dashboard to the user.

I want to fetch the data using AJAX in the client side.

amulya349
  • 1,210
  • 2
  • 17
  • 26

1 Answers1

3

https://api.stackexchange.com/docs#users Should give you a place to start.

Below is the ajax call to get the Reputation of a specific user in this case its userid 4944823

    $.ajax({
        url: 'https://api.stackexchange.com/2.2/users/4944823?order=desc&sort=reputation&site=stackoverflow',
        success: function (response) {
            debugger;
            if (response.items.length > 0) {
                self.reputation(response.items[0].reputation);
            }
        },
        error: function () { },
    });
StackRewind
  • 358
  • 3
  • 5
  • I already had there. But, it has different API endpoints for questions, answers etc. So, I have to make multiple ajax calls to fetch the data. I want a better solution to this. – amulya349 May 28 '15 at 12:38
  • Had a read through the docs doesn't seem like there is a way using the API to batch request to different endpoints together. May I ask why you don'y want to make multiple calls? – StackRewind May 28 '15 at 12:49
  • Because, when I am making multiple ajax calls, as its asynchronous, Its showing the outputs before getting the responses of the ajax calls. I need a way so that I would get the outputs once all the requests are finished. – amulya349 May 28 '15 at 13:23
  • you could wrap all the the ajax request as outlined in [Wait until all jQuery Ajax requests are done?](http://stackoverflow.com/questions/3709597/wait-until-all-jquery-ajax-requests-are-done) – StackRewind May 28 '15 at 13:31