Search code examples
stackexchange-apidataexplorer

How to get the Timestamp of awarded time for badges?


Which is the way to take the time of a badge awarded to a user?

I tried the notification as it is recommended here but I get:

method not available

Solution

  • Per the linked answer and the API docs, you cannot directly get the badge award times from the API.
    To get them indirectly requires a fair bit of work, which is already summarized in that answer and which you did not do. Also, the indirect method is limited to a single, logged-in, user per app session.

    Perhaps a better approach is to use the Data Explorer (SEDE).

    Here is a query to get a user's badge award times.
    See it in action at SEDE: data.stackexchange.com/stackoverflow/query/851077/...

    -- UserId: User ID     "Enter a user's ID."
    SELECT      u.Id     AS [User Link]
                , CASE
                    WHEN b.Tagbased = 1 THEN 'Tag: [' + b.Name + ']'
                    ELSE b.Name
                END    AS [Badge name]
                , CASE
                    WHEN b.Class = 1 THEN 'Gold'
                    WHEN b.Class = 2 THEN 'Silver'
                    WHEN b.Class = 3 THEN 'Bronze'
                    ELSE '*Unkown*'
                END    AS [Class]
                , b.Date AS [Awarded]
    FROM        Badges b
    LEFT JOIN   Users u  ON u.Id = b.Userid
    WHERE       b.Userid = ##UserId:int##
    ORDER  BY   u.Displayname
                , [Awarded] DESC
    


    It returns results like:

    User Link   Badge name        Class      Awarded
    Lenak       "Editor"          "Bronze"   "2018-05-02 10:04:38"
    Lenak       "Custodian"       "Bronze"   "2018-05-02 09:49:36"
    Lenak       "Peer Pressure"   "Bronze"   "2018-04-26 22:18:46"
    Lenak       "Informed"        "Bronze"   "2018-04-26 20:38:26"