Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
API?
eleith
New
i've got four categories in my forum. i'ld like an API where i can get the top 3-5 newest discussions in each category, and build a simple 'getsatisfaction' like feedback popup box for casual users to introduce them to the forums.
before diving into the code, wanted to see if someone's done something similar already, or if someone's got pointers of where i can start poking. i am imagining this is a pretty simple php script that will pump out json data for what i need, so shouldn't take long to put together.
before diving into the code, wanted to see if someone's done something similar already, or if someone's got pointers of where i can start poking. i am imagining this is a pretty simple php script that will pump out json data for what i need, so shouldn't take long to put together.
0
Comments
http://vanillaforums.org/addon/542/api
it's a very bare bones application, that really only meets a particular need at the moment (a get satisfaction like widget interfaced to a vanilla forum), but perhaps this could kick off something much more robust?
in the end, i think if you need a particular API and can't wait for @todd or @mark to release a robust REST api, this application would be a good starting place. my approach was basically to look at /vanilla/controllers for the page i wanted to mimic with an API, cut out the cruft, and migrate it into the api controller that outputs json.
hope this helps someone!
install the application, and go to /api/category, and you'll see a list of all your categories, four discussion titles for each category, and even userid/key (if logged in). however, it will all be JSON encoded. this just means the information is inside an javascript object, such that an ajax call can turn this information into variables that can be used by javascript running on a webpage.
i could have output the information in XML, text files, but since i was wiring it up to an ajax call, it made sense for me to use JSON.
if you wanted to use it in a wordpress, you'ld need a wordpress plugin that could consume the JSON and do something with it (thus, it would have to be written by someone that knew about this application). unfortunately, that means you can't be code free.
did you have something in mind already of how you wanted to use information like this?
@GMAntonz
if you needed just that, i could modify the application. i could add the api to do something like this
/api/discussion?id=5
and that would show all the posts for that discussion. i'm happy to modify it if it was just that, but it would also be trivial to change the file controller/discussion api and add that api as well.
let me know
http://code.google.com/p/json-template/
I'm not 100% certain yet, but those may be of assistance I reckon.
Thanks for replying
seems like no matter what, you're going to have to get your hands dirty in code however, because you'll need somewhere in the chain to tell the templating system what the JSON looks like.
if you knew a developer who has written even the most trivial wordpress plugins, you could just show them the API page, and tell them what you want, and i bet they could get you a working plugin in a couple of hours. that would be a lot faster than trying to find a mixmash of the right plugins to throw on top of each other and make this work.
transforming the JSON this API outputs to html is pretty simple, and wouldn't need the libraries you've referenced (they're overkill, unless you have this need over and over again).
basically what I am looking to do is integrate vanilla2 into my website, where when I make an article there will be a discussion thread for the comments on that article. I want to integrated into the article page to display all the comments made on the article and have the option of adding a comment.
for example, you want to pass in a discussion id and then get back posts on that discussion. what in particular do you need to know about the posts? text, title? username? etc etc.
spec it out for me, and i'll post an update to the application when you do.
Basically what I envision is the article page will pass on the discussion id for the discussion thread which has been designated to this article. This will return all the posts so far in that discussion with username who posted the post, their avatar, time and date of post, if possible the number of post (comment #3, #4, etc), and ofcourse the text of the post.
I would also want it to return somewhere a total number of posts in this discussion, if possible.
At the end of the posts I envision the add comment box where if you're logged in you can add your own comment to the discussion thread, much like right here in vanilla2. Right now as I understand it, the API adds a new discussion thread, but I would want to add a post to an already existing thread that's being displayed.
Hope this provides you some more information.
http://vanillaforums.org/addon/542/api
updated the application. i haven't tested the comment/add API, but i tested all the others, and it should get you most of the way there. i think you'll have to figure out how to get the avatar working though, i didn't look into it, but all other data should be there just by inspection of the output.
in order to add, you'll need the transient key of the current users session, so you'll need to call /api/session to get that. (i think you need to do this even if the users is logged out, but you might want to test this one if you want to support non logged in users)
in general, i've modified the APIs so the output matches the internal class members used internally by vanilla to be more consistent.
let me know if this gets you to where you need to build your comment module.
my forum is integrated with vanilla through single sign on, so i make all server-side request to this API though a proxy i wrote, that allows me to make request while mimicking the user session for our service.
you might be getting a bonk, because the API expects a user session, and there is none. i'll update it to return something more sane, instead of hitting a php error.
in the end, you'll need to make a http request and pass in your services cookie, or a vanilla session cookie. i'm using python urllib/urllib2, in php you'll need a combination of file_get_contents and stream_context_create
look at example #4: http://php.net/manual/en/function.file-get-contents.php
you'll need to pass the header of the user cookie. the http header looks something like this:
"Cookie: key=value; domain=www.mydomain.com; expires=GTM expire date; path=/;"
the value needs to be urlencoded.
this was a lot to parse, but i think once you get a few examples up and running you'll comprehend it pretty quickly.
There's already a list of users "In this Discussion" so it would be great to be able to use that list for autocompletion in the text area I reckon
sure. the participating users of a forum are available in the api/discussion?id=x call. it just had to be parsed out and passed into the autocomplete plugin.
as for backporting, this would depend on how much has changed for the application structure, and db related calls. i imagine the answer is no.
i need single-sign-on, thus i'm only working with v2 currently.
updated the application to push out a GUEST user transactionkey/userid instead of hitting a php error in api/session calls.