Display Dynamic Posts

ScribbleLive is all about real-time, so it makes sense that you want to display posts dynamically as they’re added to an event. Here’s the API call you’ll want to make:

/event/{event id}/all/?Token={API Token}&Since={Last Modified Time}

The since parameter is the important part. Each event-level API call returns the date and time the event was last modified. Pass that date as the since parameter to check for new updates.

Note: This call is limited to return posts from the past seven days.

The lastmodified parameter in the response isn’t in the proper format to send back as the since parameter, here’s how to fix it using Javascript:

this.LastModifiedTime = eval("new " + (pResponse.LastModified.replace(/\//g, ""))); 

var LastModifiedTimeFormatted = this.LastModifiedTime.getUTCFullYear() + "/" + (this.LastModifiedTime.getUTCMonth() + 1) + "/" + this.LastModifiedTime.getUTCDate() + " " + this.LastModifiedTime.getUTCHours() + ":" + this.LastModifiedTime.getUTCMinutes() + ":" + this.LastModifiedTime.getUTCSeconds();

Assuming pResponse.LastModified is the LastModified parameter sent back by the API, LastModifiedTimeFormatted is the variable you should send as the since parameter.

Here’s the full process for displaying and updating an event:

  1. Get the last page of posts, display them, and save the LastModified time.
  2. Format the LastModified time.
  3. Send the formatted LastModified time back as the Since parameter.
  4. Display the new posts and save the LastModified time.
  5. Format the LastModified time.
  6. Send the formatted LastModified time back as the Since parameter.
  7. Repeat.

Get started with our open source javascript project. It does all of the heavy lifting for you.