elgg webservices rest api - returning all site wire posts

Hi All

I am trying to get all the wireposts that have been posted onto the site to show on the rest api. In my case I am using JSON.

Here is my code

/**

*test to see if wire works with web services

*

*expose function and all that

*/

function everyone_wire_rest(){

 

$river_wire = get_river_items(0,0,'','','thewire','',20,0, 0,0);

 

 

foreach ($river_wire as $river){

 

$result []= get_object_entity_as_row($river->object_guid);

 

}

 

return $result;

 

}

 

this responds

 

{"status":0,"result":[{"guid":"46","title":"","description":"and this should show another in JSON"},{"guid":"45","title":"","description":"a test post to the wire"}]}

 

and I can parse and use this fine. 

 

However, the problem is that not a lot of information is shown doing it this way. For example, I cant actually find out who wrote it, the time etc. 

 

I know the way I have done it is a bit of a work around but it is the only way that I could find. Does anyone else have any ideas?

 

Thanks a lot!

 

 

 

 

 

 

 

 

  • get_river_items() only reads the elgg_river tbl,

    ==>

    Elgg178/views/default/river/item/list.php

    the (missing) view you'll need to call for all the detailed info ;) 

     

  • You want to use elgg_get_entities() to get the latest wire posts

  • both data fetchs will work ok - depends on what you're interested in..

    ps - send me yr code if wanna me to look at or help debug if problms ;-)

  • using elgg_get_entities it doesn't show in JSON on return. It shows three {} which is how many wire posts there are but I can get it to throw in the whole array. Any ideas?

  • Just to make sure the conversion from objects to JSON is working trying doing this:

    $obj = new stdClass();

    $obj->description = "My test description";

    $obj->guid = 42;

    return $obj;

    The web services API should handle turning this into JSON after it is returned.

  • Hi Cash.

    That resonds fine as expected.

    Here is my code

    $thewire = elgg_get_entities($options = array('types'=>'object','subtypes'=>'thewire'));

    foreach($thewire as $post){

    $result_wire [] = $post;

    }

    return $result_wire;

    it returns an array as I can see from going to the 'default' view. I might do a work around and just list what I need. For example

    foreach($thewire as $post){

    $result_wire->description = $post->description;

    $result_wire->owner_guid = $post->owner_guid

    }

     

    this way only responds the first wire post

  • so i can now get the posts showing again by doing

    $thewire = elgg_get_entities($options = array('types'=>'object','subtypes'=>'thewire'));

     

    foreach ($thewire as $post){

    //$result_wire = new stdClass();

    $result_wire[] = get_object_entity_as_row($post->guid);

    }

     

    return $result_wire;

     

    but this still isnt showing the owner_guid and everything. I really cant seem to figure this one out and its causing a real head ache :/

  • I have found a solution that works perfectly

    $thewire = elgg_get_entities($options = array('types'=>'object','subtypes'=>'thewire'));

     

    foreach ($thewire as $post){

    $wire_result = new stdClass();

    $wire_result->guid = $post->guid;

    $wire_result->description = $post->description;

    $wire_result->owner_guid = $post->owner_guid;

    $wire_result->time_created = $post->time_created;

    $wire_result->username = get_user($post->owner_guid)->username;

    $result_wire[] = $wire_result;

    }

     

    return $result_wire;

     

    }

    it means I have to manually state everything I want but it has the advantage of me suppling extra information too.

     

    Thanks for all your help!