1

I'm trying to implement a simple rep list, much like as seen on Stack Exchange sites.

What I would like is to get three things: the rep change amount, type of change, and question title.

However, the reputation changes API gives me only the rep change & type, and I'm left in the dark as to the question title.

How should I go about getting the associated title for a given rep change?

1 Answer 1

1

This would be a two-step process if the /posts/{ids} path returned title, but it doesn't. Since the /answers/{ids} path, does return title (with an optional filter setting), then it should be easy-ish for /posts/{ids} to do so as well. Perhaps this would be a good feature request?

Anyway, as it stands now, you must do this in pages and in 3 steps per page. Here's the pseudocode:

  1. Get the first page of reputation entries. Fortunately, these seem to be sorted by date in descending order.
    Set the pagesize to it's maximum value for this path (100).

    For example, call:

    /2.1/me/reputation-history/full?page=1&pagesize=100&site=stackoverflow&filter=!9j_cPmQ8n

    and get results like:

    {
      "total": 4284,
      "page_size": 100,
      "page": 1,
      "type": "reputation_history",
      "items": [
        {
          "user_id": 331508,
          "creation_date": 1375825981,
          "post_id": 3657953,
          "reputation_change": 5,
          "reputation_history_type": "post_upvoted"
        },
        {
          "user_id": 331508,
          "creation_date": 1373713575,
          "post_id": 17615370,
          "reputation_change": 15,
          "reputation_history_type": "answer_accepted"
        },
        // etc., etc.
      ],
      "quota_remaining": 9993,
      "quota_max": 10000,
      "has_more": true
    }
    

    These will be the user's most recent rep changes (up to 100). Most of the time, it will be all you need -- unless the users scrolls down for more.

  2. Collect the post_ids into a semicolon-separated list. EG: 3657953;17615370.
    Post ID's may be duplicated so, ideally, remove duplicates here -- to save bandwidth in the next steps.

  3. Feed those id's into the /questions/{ids} path, using pagesize=100 and filter=!J4Lov0xb.M. For example:

    /2.1/questions/3657953;17615370?pagesize=100&site=stackoverflow&filter=!J4Lov0xb.M

    Yielding results like:

    {
      "total": 1,
      "page_size": 100,
      "page": 1,
      "type": "question",
      "items": [
        {
          "question_id": 3657953,
          "score": 8,
          "title": "How do I get the jQuery-UI version?",
          "tags": [
            "jquery",
            "jquery-ui",
            "greasemonkey"
          ]
        }
      ],
      "quota_remaining": 9953,
      "quota_max": 10000,
      "has_more": false
    }
    

    Important:

    1. If the post_id belongs to an answer, it will not appear in these results; that's okay.
    2. The question_id will match the post_id passed in when said post_id is for a question.
    3. The results may not be in the order of the id's that were passed in.


  4. Feed those id's into the /answers/{ids} path, using pagesize=100 and filter=!FqMlbofLCbbHPWmQsFIonPgq86. For example:

    /2.1/answers/3657953;17615370?pagesize=100&site=stackoverflow&filter=!FqMlbofLCbbHPWmQsFIonPgq86

    Yielding results like:

    {
      "total": 1,
      "page_size": 100,
      "page": 1,
      "type": "answer",
      "items": [
        {
          "question_id": 17614067,
          "answer_id": 17615370,
          "score": 1,
          "is_accepted": true,
          "title": "addEventListener and setInterval fail silently in a Greasemonkey script",
          "tags": [
            "javascript",
            "greasemonkey",
            "setinterval",
            "addeventlistener"
          ]
        }
      ],
      "quota_remaining": 9945,
      "quota_max": 10000,
      "has_more": false
    }
    

    Important:

    1. If the post_id belongs to a question, it will not appear in these results; that's okay.
    2. The answer_id will match the post_id passed in when said post_id is for an answer.
    3. The results may not be in the order of the id's that were passed in.


  5. Combine the title values, obtained in steps 3 and 4, with the reputation entries from step 1, by keying off the appropriate ID's.

  6. Voilà, done in 5 easy steps (per page of results)!

  7. Repeat steps 1-6 for additional pages of reputation entries, only on user demand.

4
  • Yeeesh, that's a ton of network activity, especially on mobile. I guess that's just how it's done, though :P
    – user18962
    Commented Aug 7, 2013 at 2:53
  • You can cut it down if we make, and they implement, that feature request. There's no reason that I can see why /posts/{ids} shouldn't be able to return the title. Commented Aug 7, 2013 at 2:56
  • I'm tempted to write a server-side thing to do all that for me - but then I have scaling, etc. to deal with.
    – user18962
    Commented Aug 7, 2013 at 3:00
  • It's only 3 API calls per page, and most users will only request the first page. Let the client App make the calls. If your server makes them, it may bust your daily quota. (Quota is by app and by IP.) Commented Aug 7, 2013 at 3:08

You must log in to answer this question.