Can You Embed Individual's Discourse Stats Live on a Web Page?


#1

(Not sure if this is the correct place to ask this, but if not I’d appreciate being pointed in the right direction)

The site I’m looking to develop features account profiles (beyond what what be featured in an individual’s discourse profile) and I’m curious if there is a way to have a running total of their discourse stats (# of posts, likes, etc) automatically fed into this other account?

Bonus Questions:

If this is possible, would it be practical to have this in 40+ profile previews on an aspect of a site where people browse all the profiles on the site? Or would it take too long to load all of these?

Is this a hard thing to develop?

Any help answering this would be greatly appreciated!


#2

Not sure about your performance practicality question, but have you had a chance to check out the API documentation? That may be your best starting point.


(Kane York) #3

You probably want the endpoint /users/:username.json.

{
  - user: {
    - stats: [
{
action_type: 4, // created topics
count: 161,
id: null
},
{
action_type: 5, // created posts
count: 10218,
id: null
},
{
action_type: 6, // ?? "response"
count: 5491,
id: null
},
{
action_type: 1, // likes given
count: 6279,
id: null
},
{
action_type: 2, // likes recieved
count: 7913,
id: null
},
{
action_type: 7, // Mentions
count: 921,
id: null
},
{
action_type: 9, // Quotes ??
count: 335,
id: null
},
{
action_type: 11, // edits
count: 75,
id: null
}
],

(Ryan Wanger) #4

I was using this and it worked great up until very recently. Now [“stats”] isn’t returned by this endpoint. Any idea how I can get it?


(Joe Buhlig) #5

Looks like it was moved from a parameter to hardcoded.


(Ryan Wanger) #6

I saw that while poking around, but I was sure that it had worked for me since the date of that edit. I guess not!

So…I’m out of luck then? Or is there another way to get them?


(Kane York) #7

The stats themselves were moved to /my/summary - follow the steps for “Reverse Engineering the Discourse API” for that page.


(Ryan Wanger) #8

Got it - thanks for the help!

  response = @discourse_client.get("/users/#{username}/summary.json")
  stats = response["body"]["user_summary"]

{"likes_given"=>3, "likes_received"=>0, "posts_read_count"=>307, "days_visited"=>62, "topic_count"=>0, "post_count"=>1, "time_read"=>"2h", "topic_ids"=>[], "replies"=>[{"post_number"=>2, "like_count"=>0, "created_at"=>"2015-08-25T19:02:25.744Z", "topic_id"=>50}]}