CodeSlinger1 does not currently provide support for this item.

14 comments found.

Hi CodeSlinger, I love posterous – need a bit more info. though – can it re-size post images and also pull in the posterous galleries from a post – and possibly the auto generated mp3 player – Cheers AL.

Hi ADesign1,

Yes it can resize Post Images via the inline image tag. Please take a look at the usage_demo.php file’s post example to see how it is done.

I’m working on expanding the API Client to add pulling in Galleries from a post, and hope to push an upgrade in the near future.

Auto Generated MP3s are not currently exposed in a stable version of the Posterous API .


Code Slinger

Hi CodeSlinger, Have implemented this – but all I am getting is the JSON response code showing on the page rather than the actual posterous blog ?

Hi ADesign1,

Can you please clarify what you are trying to do with the API , as in what call are you making? Also, most JSON responses for the API calls contain the information. So for example if you make a call to get comments for a post, the comments will come back as JSON , and you can then echo out each comment in PHP .


Code Slinger

Hi, Have just used your usage_demo.php script to see what the result would be – was looking for the codeslinger.posterous site to show up? – the site I am going to get posts from uses the same ‘fluid’ theme BTW ( ) – Cheers AL

Ah ok, so if you have the username email and password for the blog , then by calling:

$posterousClientLocation=dirname( FILE ).’/PosterousClient.php’; require_once($posterousClientLocation);

$posterousClient = new PosterousClient('[POSTEROUS EMAIL]','[POSTEROUS PASSWORD]');

$input = array(‘page’=>‘1’, ‘since_id’=> ‘0’ ); $response = $posterousClient->getPosts($input);

You should get the first page of posts back in JSON format. Are you seeing that?

yep – here is a test page on a test site calling the webrobot site -


Now that the JSON is coming back we can parse it using PHP . So for example if the json string is $response:

$jsonObject = json_decode($response);

This would print out the field display_date within that JSON object. So you would use the json object to get the posts information and then display then on your page and style it in any case that you wish. Does this make sense?

Do you mean I have to add this line to my php include?

Ok, so in your current code, you’re making the call, which should look something like this:

$response = $posterousClient->getPosts($input);

Now the response of this call is a json string, so to be able to get elements within that json response, you need to cast the string into a Json Object:

$jsonObject = json_decode($response);

Once you have this line on your php file, you can get elements within this json object using the following notation:

$jsonObject->{‘[JSON FIELD NAME ]’};

OK – so far so good, how do I interpret the posterous/json field names?

So you can see the JSON coming back. For example on the JSON on your test page:

user 00:41:59 -0700”,nickname Robot”,profile_pic class=\”posterous_bookmarklet_entry\”\u003E\r\n\u003Cdiv class=\”posterous_quote_citation\”\u003Evia \u003Ca href=\”

To get the user who created the post:


To get the post id

$postUser = $jsonObject->{‘id’};

To get the HTML Body of that post:

$postBody = $jsonObject->{‘body_html’};

This is the standard way of getting data from a JSON object. For more examples of how to get information from a JSON Object, please refer to the following article:

Hope this helps!


Code Slinger

Just trying this out…

Accessing posts as a list and by id is working fine from my Posterous site but when I try to get specific data in the way you suggested above I get an error e.g.

50 $jsonObject = json_decode($response); 51 $postBody = $jsonObject->{‘body_html’}; 52 echo $postbody;

Gives me…

Notice: Trying to get property of non-object in …/posterous/usage_demo.php on line 51

Hi Cfoinfo,

This is because the JSON response for getPosts returns a collection of Post Objects. So to get say the body of the very first post in that collection, I would use the following notation:

$jsonObject = json_decode($response);
$aPost = $jsonObject[0];
$body =$aPost ->{'body_html'};

Please let me know if this solves your problem.


Code Slinger

Thank you, that worked fine. Then I tried to use a loop but failed…

$jsonObject = json_decode($response); foreach($jsonObject->post_id as $post) {echo ’.$post->body_full’;}

I assumed the post_id could be used as a key and body_full as a value.

Eventually what I’m trying to do is get a list of say the last 10 posts but also filtered by content type e.g. with image posts in one array, with mp3 posts in another with video posts in another etc.

I can then put these individual arrays into a tabbed UI on my php page.

If the API can do this then I would be happy to pay you for the custom json/php code snippet to do this as I think it’s way beyond the support anyone should expect from a $2 spend :)

Hi Cfoinfo,

Since post_id is at the same level as body_full, I don’t think you can use it like a key-value pair in the loop. I think the for loop needs to be like the following:

foreach($jsonObject as $post) { $body = $post -> ‘body_full’; $postId = $post -> ‘post_id’; echo($postId.$body);


Thanks again – that worked.

Agree with @cfoinfo above – customer support above and beyond a $2 spend.

5* rating from me.

If I could offer my 2cents worth – the inclusion of a text file with a pre made snippet parsing the last, say 5 posts from a posterous blog and returning the title, main image, date, user and post body would make it 100 times easier for php rookies ( like me!) to get this excellent CC item up and running.

Cheers AL.

Just in case this helps someone else who wants to separate out different types of Posterous posts…

$jsonObject = json_decode($response); foreach($jsonObject as $post) { $image = $post >{‘media’}[2]>{‘images’}[0];

if($image !=’‘){ $body = $post -> {‘body_full’}; $nickname = $post >{‘user’}>{‘nickname’}; $date = $post -> {‘display_date’}; }}

This seems to work and for other post types e.g. videos and audio_files

works great – but can you include a better way to get all attachments (imags,video,audo) out easily when using getPosts

this would be a big help



Sure thing, I’ll add that as an enhancement in the next update of this component!


Code Slinger

Hello admin ,may you explain to me how this script work?