Sign in to follow this  

Loading tweets & limiting characters with JSON

Recommended Posts

Mr.XXIV    250

This script basically lets me load tweets and user info with jQuery. The problem is, I don't have the right url to load the timeline instead of the public search query, I do, but it doesn't load. Also, I'm able to use the substring, but I don't know how to make "..." happen when the length has reached. I'm guessing I'd have to make an if/else statement to match the length for equal to or less using .length.

I uploaded a screenshot of what I basically have for my site, the results of the tweet bar.

<ul id="illest-tweets">
<script id="tweets-template" type="text/x-handlebars-template">
  {{#each this}}
   <img src="{{thumb}}" alt="{{author}}">
   <b>{{author}}</b><br />
   <a href="{{url}}">{{tweet}}</a>

<script src=""></script>
<script src=""></script>
var Twitter = {
init: function( config ) {
this.url = '' + config.query + '&callback=?&rpp=4';
this.template = config.template;
this.container = config.container;
attachTemplate: function() {
var template = Handlebars.compile( this.template );
this.container.append( template( this.tweets ) );
fetch: function() {
var self = this;
$.getJSON( this.url, function( data ) {
self.tweets = $.map( data.results, function( tweet ) {
return {
author: tweet.from_user,
tweet: tweet.text.substring(0,100),
thumb: tweet.profile_image_url,
url: '' + tweet.from_user + '/status/' + tweet.id_str
// For future lessons, research $.deferred, viewers. :)
template: $('#tweets-template').html(),
container: $('#illest-tweets'),
query: 'illest'


Share this post

Link to post
Share on other sites
Mr.XXIV    250

Sorry for the double post, the forum wouldn't let me edit it anymore.

I know that this would work. But, I don't know where to put since it will cause an error within the function.

var tt = tweet: tweet.text

if(tt.length === 80) {
	 tweet: tt.substring(0,100)
} else {
	 tweet: tt.text

Edit: Actually no, I have a part of it, but I'd need to add "...".

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.