How to Embed Stackexchange Account Metrics into WordPress?

How can I embed Stackexchange reputation scores and badge counts into my WordPress blog? I want to show on my blog a small table with accounts as rows and columns consisting of rep scores and badge counts. Any ideas on how to do this?

Related posts

Leave a Reply

3 comments

  1. Here’s a testing code I already had for consuming Stack Exchange API:

    <?php
    /**
     * Plugin Name: Print SE-API Results as Admin Notice
     */
    
    add_action( 'admin_notices', 'b5f_consume_se_api' );
    
    function b5f_consume_se_api() 
    {
        $user = '1417894';
        $page_size = '&pagesize=3';
        $order = '&order=desc';
        $sort = '&sort=votes';
    
        $so = wp_remote_get( 
            'http://api.stackexchange.com/2.1/users/'
            . $user
            . '/answers?site=stackexchange'
            . $page_size . $order . $sort ,     
            array(
                'timeout'     => 120, 
                'httpversion' => '1.1' 
            ) 
        );
    
        if ( $so['response']['code'] == '200' )
        {
            $so_array = json_decode( $so['body'], true );
            var_dump( $so_array['items'] );
        }
    }
    

    This is the URL being consulted and its JSON result. It returns the last 3 answers from the OP, sorted by votes (descending).

    Check the docs and adapt everything to suit your needs.