Create a custom drupal API
bmn - April 2, 2009 - 06:54
Hi,
We are using drupal as our social networking site at the moment, but we would like to integrate it further into our main site, ie displaying pictures/videos/threads on the main site which link through to the drupal site. I was just wondering whether this was possible. I know there is RSS, but this doesn't provide a method of sending back the 'highest rated' images and their rating etc.
I was just wondering if there was a drupal module out there that provides an api to fetch this kind of information; or will I have to write one myself?
Any help would be greatly appreciated.
Cheers,
Ben

You can use Views to return
You can use Views to return xml which contains all data - would that be helpful? I know of two modules that do this:
http://drupal.org/project/views_datasource
http://drupal.org/project/views_node_feed
Great thanks! I'll have a
Great thanks! I'll have a look into these modules. I suppose the alternative way would be to extend the xmlrpc calls with my own xmlrpc endpoints.
A custom module is always an
A custom module is always an option of course. The book Pro Drupal Development contains a good chapter about Drupal & xmlrpc, in case you need some documentation.
views_datasource seems to do
views_datasource seems to do the trick.
I can now get nice XML output from the view, but I can't seem to get the rating's from fivestar out as part of the xml document. I have fivestar enabled in the content type, but as I haven't 'defined' a content field for fivestar, I cant add it in the Views constructor. I tried to do this by selecting 'Fivestar Rating' as the field type, but this then doesn't allow users to use the ajaxy voting system, it simply prints out the stars that the author selected when uploading the image/video.
Do you know if its possible to get the fivestar rating out and into the views somehow? I can't seem to find anything via search. I'm using Drupal 6.10.
Thanks in advance.
Cheers,
Ben
Views is a database query
Views is a database query builder, so it can show you anything that's in the database. The rating of a node can be retrieved (as you found out), but the user interface to rate it yourself is not data, it's functionality which depends on the drupal core. This means you cannot simply export it as xml and place it on another website. You would need to re-create the rating interface on the other site and find a way to send the rating to the drupal site so it can be processed there. Maybe there is a module for this, otherwise, i think some custom xml-rpc stuff should do the trick.
thanks for the feedback. I
thanks for the feedback.
I think I have worked it out though. I needed to create a relationship between the node and the Voting API. Now I can select the fivestar rating field as part of the output & filter. :)
OK, that's an interesting
OK, that's an interesting feature, but does it mean that you can export this view as XML and use the rating field on an external, non-drupal site? Once you get this working, I'd be interested to read how you did it.
Exactly. As for how I did
Exactly.
As for how I did it...
I created a 'video' content-type and added a few custom fields, along with an embed field via (http://drupal.org/project/emfield). I also enabled fivestar ratings to this particular content-type.
I then created a new XML video feed of type 'node' in the Views panel
Then under the relationship section of the view I added a new relationship, it then asked to what i would like to create it, and i picked: 'Node: Voting results'. I think I had to make sure I had enabled
Under fields I could then select 'Voting API results: Value' from the field listing (right at the bottom of the list for me).
Screenie of the view: http://bmn.name/images/drupal_fivestar_rating.png
The resulting XML looks like this:
<node><nid>12</nid>
<title>Testing the rating</title>
<view_node><a href="/node/12">view</a></view_node>
<created><em>3 days 2 hours</em> ago</created>
<type>Video</type>
<uid>1</uid>
<name>bmn</name>
<field_video_embed>
<a href="/node/12"><img src="http://img.youtube.com/vi/Hy7c97r-sko/0.jpg" width="150" height="112" alt="See video" title="See video" /></a>
</field_video_embed>
<value>100</value>
<comment_count>0</comment_count>
</node>
Hope this helps, I can explain more if that didn't make sense.
Thanks for the explanation,
Thanks for the explanation, it definately makes sense.