stackexchange-apistackexchange

Stack Overflow timeline (feeds) of a user


How to get the Stack Overflow timeline (feeds) of a user?

What are the steps to follow, if a user wants to display his or others Stack Overflow timeline/feeds in his website.


Solution

  • This document details the steps to get the Stack Overflow timeline (feeds) of a user.

    Example: A live example is available in

    https://newtonjoshua.com

    Stack Overflow: Stack Overflow is a site of Stack Exchange, a network of Q&A websites.

    http://stackexchange.com

    Stack Exchange API: We can use the Stack Exchange API to return a subset of the actions the user/users have taken on the site.

    https://api.stackexchange.com/docs

    Timeline Feed:

    https://api.stackexchange.com/docs/timeline-on-users

    Enter the ids of the user (eg: 6778969) to view the timeline of the user. The complete url for the GET request will look like,

    https://api.stackexchange.com/2.2/users/6778969/timeline?site=stackoverflow

    Code snippet:

    //You can replace the timeline_type with a detailed descrition as given below.
    var timelineType = {
        accepted: 'Accepted An Answer',
        answered: 'Posted An Answer',
        asked: 'Asked A Question',
        badge: 'Earned A Badge',
        commented: 'Posted A Comment',
        reviewed: 'Reviewed A Suggested Edit',
        revision: 'Edited A Post',
        suggested: 'Suggested An Edit'
    };
    
    var formattedFeeds = [];
    
    $.get('https://api.stackexchange.com/2.2/users/6778969/timeline?site=stackoverflow&filter=!))x30_z', function (feeds) {
            feeds.items.forEach(function (feed) {
            var formattedFeed = {};
            formattedFeed.timeline_type = timelineType[feed.timeline_type];
            formattedFeed.title = feed.title || feed.detail;
            formattedFeed.detail = feed.detail || '';
            formattedFeed.creation_date = new Date(feed.creation_date * 1000);
            formattedFeeds.push(formattedFeed); 
        });
    });
    

    You can display the contents of formattedFeeds in your website.