1. Post #1
    Moderator Illuminati
    Hexxeh's Avatar
    June 2006
    5,091 Posts
    The Facepunch API is now almost ready for public consumption. I've just written up some basic documentation and had cosmic duck throw a site together for it.

    You can now view the documentation and use the shiny new API console at the following address: http://facepun.ch

    Please post any bug reports or suggestions in this thread so I can keep track of them. Any improvements to the documentation are also welcome.

    If you're interested in developing an application based on the API, feel free to add me on Steam, and I'll be happy to answer questions regarding the API there too.
    Reply With Quote Edit / Delete Reply Mac United Kingdom Show Events Programming King Programming King x 33Winner Winner x 4Useful Useful x 2Friendly Friendly x 1 (list)

  2. Post #2
    Jvs
    PENISCorp's First Employee
    Jvs's Avatar
    June 2009
    1,581 Posts
    I think I've found a problem when using the API console itself,it just doesn't send the content of newreply's message.
    This was the message I tried to send in,it just didn't append anything to the post message.
    This is quite nice,pretty fast and the responses are lightweight compared to having to scrape everything yourself.
    This post was sent via the api console mainly as a test.
    Also,when are you going to do the api usage monitor you were talking about on waywo?
    URL: http://api.facepun.ch/?username=Jvs&password=redacted&action=newreply
    Post body: thread_id=1162943&message=
    The response was of course null,and I authenticated and rated the op via the console just to check.
    Reply With Quote Edit / Delete Reply Windows XP Italy Show Events Funny Funny x 1 (list)

  3. Post #3
    Moderator Illuminati
    Hexxeh's Avatar
    June 2006
    5,091 Posts
    Should be fixed.

    Also, usage monitor is in the works right now.
    Reply With Quote Edit / Delete Reply United Kingdom Show Events Friendly Friendly x 1Agree Agree x 1 (list)

  4. Post #4
    Gold Member
    Hey0's Avatar
    July 2007
    264 Posts
    Awesome! Little bug report, the post count being returned for users is incorrect, it ignores numbers after the comma, and threads in the mass debate forum return a 500 error.

  5. Post #5
    Moderator Illuminati
    Hexxeh's Avatar
    June 2006
    5,091 Posts
    Awesome! Little bug report, the post count being returned for users is incorrect, it ignores numbers after the comma, and threads in the mass debate forum return a 500 error.
    Fixed and fixed. The Mass Debate forum doesn't have ratings, so you won't get any rating or ratingkey data for that forum and others where ratings are disabled.
    Reply With Quote Edit / Delete Reply Mac United Kingdom Show Events Useful Useful x 1 (list)

  6. Post #6
    Gold Member
    Jookia's Avatar
    July 2007
    6,768 Posts
    Is this an actual API, or is it some kind of scraper? I mean the behind-the-scenes stuff.

  7. Post #7
    Moderator Illuminati
    Hexxeh's Avatar
    June 2006
    5,091 Posts
    Is this an actual API, or is it some kind of scraper? I mean the behind-the-scenes stuff.
    It's scraping and parsing data out of pages into JSON. However, the API servers are trusted by Facepunch, so requests appear to come from your address, not the API server address.

  8. Post #8
    PLEASE DON'T EAT ME!
    Doritos_Man's Avatar
    June 2009
    2,899 Posts
    I get a 404 on the Try it out buttons
    Reply With Quote Edit / Delete Reply Windows 7 United States Show Events Agree Agree x 1 (list)

  9. Post #9
    Moderator Illuminati
    Hexxeh's Avatar
    June 2006
    5,091 Posts
    Fixed.

  10. Post #10
    It's really stupid to require the user to send their user/pass every single request.
    Reply With Quote Edit / Delete Reply Windows 7 United States Show Events Agree Agree x 5Disagree Disagree x 1 (list)

  11. Post #11
    Gold Member
    Alex_grist's Avatar
    January 2007
    1,064 Posts
    It's really stupid to require the user to send their user/pass every single request.
    You forget about it if you make something that does it all automatically.
    Messy code: http://pastebin.com/qf0eNuFi

  12. Post #12
    RUBY OVERLORD
    swift and shift's Avatar
    November 2011
    2,115 Posts
    You forget about it if you make something that does it all automatically.
    Messy code: http://pastebin.com/qf0eNuFi
            // A function to check if the user is logged in.
            public function isLoggedin()
            {
                    if (isset($_SESSION['loggedin']) && isset($_SESSION['username']) && isset($_SESSION['password']) && $_SESSION['loggedin'])
                    {
                            return true;
                    }
            }
    

    nice encapsulation there
    Reply With Quote Edit / Delete Reply Mac Australia Show Events Funny Funny x 1 (list)

  13. Post #13
    Gold Member
    Alex_grist's Avatar
    January 2007
    1,064 Posts
    nice encapsulation there
    Messy code
    Reply With Quote Edit / Delete Reply Mac United Kingdom Show Events Zing Zing x 9 (list)

  14. Post #14
    Gold Member
    The freeman's Avatar
    October 2007
    6,504 Posts
    I am going to guess you can't post to the News Node with the API?

  15. Post #15
    Gold Member
    nicatronTg's Avatar
    July 2009
    4,698 Posts
    I am going to guess you can't post to the News Node with the API?
    It's a scraper, you won't be able to do any actions that you wouldn't normally be able to do.

  16. Post #16
    Gold Member
    ruarai's Avatar
    December 2009
    1,356 Posts
    How do i run this? There is no "The Basics" link?

  17. Post #17
    Gold Member
    Lexic's Avatar
    March 2009
    6,123 Posts
    How do i run this? There is no "The Basics" link?
    http://facepun.ch/basics.php
    Reply With Quote Edit / Delete Reply Mac United Kingdom Show Events Zing Zing x 2 (list)

  18. Post #18
    Moderator Illuminati
    Hexxeh's Avatar
    June 2006
    5,091 Posts
    It's really stupid to require the user to send their user/pass every single request.
    This is how Facepunch works, so that's what we have to do...

    The other option would be to generate a session key and store your username and password against that key on the API server, but then people would whine about passwords being stored...
    Reply With Quote Edit / Delete Reply Linux United Kingdom Show Events Funny Funny x 1 (list)

  19. Post #19
    RUBY OVERLORD
    swift and shift's Avatar
    November 2011
    2,115 Posts
    This is how Facepunch works, so that's what we have to do...

    The other option would be to generate a session key and store your username and password against that key on the API server, but then people would whine about passwords being stored...
    aren't they stored in the logs since the api uses GET requests?
    Reply With Quote Edit / Delete Reply Mac Australia Show Events Programming King Programming King x 1Useful Useful x 1Zing Zing x 1 (list)

  20. Post #20
    Moderator Illuminati
    Hexxeh's Avatar
    June 2006
    5,091 Posts
    aren't they stored in the logs since the api uses GET requests?
    Unless you enable a logging flag for your request (which isn't public, I just use it for testing), no.

    Edit: Gonna add an action for the event log later today hopefully.
    Reply With Quote Edit / Delete Reply Mac United Kingdom Show Events Winner Winner x 1 (list)

  21. Post #21
    Gold Member
    Hey0's Avatar
    July 2007
    264 Posts
    Currently all thread's statuses are "new", regardless of whether or not the thread's been read. Could you change it so that read threads are old?
    edit;
    getquote and getedit return 500 errors as well.

  22. Post #22
    Moderator Illuminati
    Hexxeh's Avatar
    June 2006
    5,091 Posts
    Currently all thread's statuses are "new", regardless of whether or not the thread's been read. Could you change it so that read threads are old?
    edit;
    getquote and getedit return 500 errors as well.
    I can't reproduce those problems, can you give me examples of requests where that happens?

  23. Post #23
    Gold Member
    Hey0's Avatar
    July 2007
    264 Posts
    I can't reproduce those problems, can you give me examples of requests where that happens?
    Trying to quote my post above gives me a 500 error. This is the url I'm using:
    Code:
    http://api.facepun.ch/?username=Hey0&password=x&action=getquote&post_id=34667776

  24. Post #24
    Moderator Illuminati
    Hexxeh's Avatar
    June 2006
    5,091 Posts
    Trying to quote my post above gives me a 500 error. This is the url I'm using:
    Code:
    http://api.facepun.ch/?username=Hey0&password=x&action=getquote&post_id=34667776
    Works for me?

    Code:
    {"quote":"[QUOTE=Hey0;34667776]Currently all thread's statuses are \"new\", regardless of whether or not the thread's been read. Could you change it so that read threads are old? edit; getquote and getedit return 500 errors as well.[\/QUOTE]"}
    Might be something I can't reproduce on a mod account, not sure. Pass debug=true as a parameter and let me know the error.

  25. Post #25
    Gold Member
    Hey0's Avatar
    July 2007
    264 Posts
    Works for me?

    Might be something I can't reproduce on a mod account, not sure. Pass debug=true as a parameter and let me know the error.
    Code:
    Notice: Undefined variable: thread_id in /var/sites/facepunch-api/reply.php on line 39
    
    Fatal error: Call to a member function getAttribute() on a non-object in /var/sites/facepunch-api/reply.php on line 16

  26. Post #26
    Moderator Illuminati
    Hexxeh's Avatar
    June 2006
    5,091 Posts
    Try now, should've fixed it.

  27. Post #27
    Gold Member
    Hey0's Avatar
    July 2007
    264 Posts
    I still get the same fatal error.

  28. Post #28
    Moderator Illuminati
    Hexxeh's Avatar
    June 2006
    5,091 Posts
    I still get the same fatal error.
    And now?

  29. Post #29
    Gold Member
    Hey0's Avatar
    July 2007
    264 Posts
    And now?
    Code:
    Fatal error: Call to a member function getAttribute() on a non-object in /var/sites/facepunch-api/reply.php on line 20

  30. Post #30
    Moderator Illuminati
    Hexxeh's Avatar
    June 2006
    5,091 Posts
    Wanna add me on Steam to continue debugging this? Might take a few more attempts.

    Edited:

    All fixed, thanks Hey0!
    Reply With Quote Edit / Delete Reply Mac United Kingdom Show Events Friendly Friendly x 2Useful Useful x 1 (list)

  31. Post #31
    Gold Member
    toaster468's Avatar
    January 2010
    3,228 Posts
    Testing the API, it works!

    Edited:

    test

    Edited:

    Hexxeh I added you my name is Honey Butt Cheerios

  32. Post #32
    Gold Member
    nicatronTg's Avatar
    July 2009
    4,698 Posts
    Really impressed with the speed for being a scraper. Less than a second for getting new posts on WAYWO is kind of impressive. I also really like the API console, props to you.

  33. Post #33
    Naarkie's Avatar
    September 2011
    319 Posts
    Is it just me, or is down? I get a 502 Bad Gateway when I try to access facepun.ch and api.facepun.ch.

  34. Post #34
    Moderator Illuminati
    Hexxeh's Avatar
    June 2006
    5,091 Posts
    It was down, fixed.

    PHP-FPM keeps dying, in a meeting at the moment but I'll investigate afterwards.
    Reply With Quote Edit / Delete Reply Mac United Kingdom Show Events Friendly Friendly x 1 (list)

  35. Post #35
    Naarkie's Avatar
    September 2011
    319 Posts
    Its down again :(

  36. Post #36
    garry's Avatar
    September 2001
    12,377 Posts
    Maybe you could make it cache older threads and posts (things that probably won't change) so it doesn't have to hit the server every time?

  37. Post #37
    Moderator Illuminati
    Hexxeh's Avatar
    June 2006
    5,091 Posts
    Maybe you could make it cache older threads and posts (things that probably won't change) so it doesn't have to hit the server every time?
    I could make read-only requests go through CloudFlare I think, would that improve the situation?

    It means those requests would appear to be from a single IP address, but any actions like posts, threads etc would still show as the requesting users IP.

  38. Post #38
    garry's Avatar
    September 2001
    12,377 Posts
    No what I mean is - if someone requests page 1 of the WAYWO thread and it's been requested before you don't really need to touch the facepunch servers at all if you've cached it.

  39. Post #39
    Moderator Illuminati
    Hexxeh's Avatar
    June 2006
    5,091 Posts
    No what I mean is - if someone requests page 1 of the WAYWO thread and it's been requested before you don't really need to touch the facepunch servers at all if you've cached it.
    The page looks different for different users. For example, mods see posts that have been deleted, I don't think users can. If we cache the version from a mod, normal users could see that data. It's a security risk sharing cached versions between users, but caching per user wouldn't be feasible.

  40. Post #40
    Gold Member
    danharibo's Avatar
    July 2006
    4,485 Posts
    The page looks different for different users. For example, mods see posts that have been deleted, I don't think users can. If we cache the version from a mod, normal users could see that data. It's a security risk sharing cached versions between users, but caching per user wouldn't be feasible.
    couldn't you cache per user group?
    Reply With Quote Edit / Delete Reply Linux United Kingdom Show Events Agree Agree x 7 (list)