Skip to content

Instantly share code, notes, and snippets.

@ryanbrink
Created July 28, 2015 20:23

Revisions

  1. Ryan Brink created this gist Jul 28, 2015.
    14 changes: 14 additions & 0 deletions query_product_hunt.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    // This is a dead-simple script that simply logs the usernames of the people who have updated a post, ordered by when they voted

    var access_token = "YOUR_TOKEN";
    var post_id = "POST_ID";
    var theUrl = "https://api.producthunt.com/v1/posts/"+post_id+"/votes?access_token=" + access_token
    var xmlHttp = new XMLHttpRequest();
    xmlHttp.open( "GET", theUrl, false );
    xmlHttp.send( null );
    votes = JSON.parse(xmlHttp.responseText).votes;

    votes.sort(function(a, b) { if (Date.parse(a.created_at) < Date.parse(b.created_at)) {return -1}; return 1; } )
    for(i = 0; i < votes.length; i++) {
    console.log(votes[i].created_at + " " + votes[i].user.username);
    };