Question

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?

Was it helpful?

Solution 2

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.

OTHER TIPS

You could you use User Flair for this:

https://stackoverflow.com/users/flair

Add a text widget your sidebar and paste your flair HTML code in it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top