Embedding Twitter in Drupal without any additional modules
Many people are now using twitter to keep friends, clients and others updated on what they’re doing - as such we often get asked about embedding twitter information in websites when clients come to see us.
There are several modules available within Drupal such as the obviously named twitter, but sometimes this can be a bit of an overhead if you're not wanting to do any more than display tweets on a webpage. All is not lost though, as twitter information can be easily embedded in a Drupal site without requiring any additional modules.
Twitter provide a ‘widget’ at http://twitter.com/goodies/widget_profile that can be embedded in any webpage - it consists of some html that calls javascript and css on the twitter site and is can be customised with different colours, layouts etc. After choosing the various options, click the ‘finish and choose code’ button and HTML looking something like the below is produced:
<div id="twtr-profile-widget"></div>
<script src="http://widgets.twimg.com/j/1/widget.js"></script>
<link href="http://widgets.twimg.com/j/1/widget.css" type="text/css" rel="stylesheet">
<script>
new TWTR.Widget({
profile: true,
id: 'twtr-profile-widget',
loop: true,
width: 250,
height: 300,
theme: {
shell: {
background: '#3082af',
color: '#ffffff'
},
tweets: {
background: '#ffffff',
color: '#444444',
links: '#1985b5'
}
}
}).render().setProfile('simonhanmer').start();
</script>
This code can be embedded in a standard Drupal block (although you'll probably want to replace the twitter name in the setProfile call) - simply login as an administrator, or a user with permission to post full html code and
- Navigate to Administer » Blocks » Add Block
- Specify an appropriate description for the block - ”Twitter“ seems appropriate
- Paste the code generated for the twitter widget into the body
- Ensure that you've changed the Input Format to 'Full HTML'
- Complete any other appropriate fields, such as pages for the block to appear on
- Click ‘Save Block’
- Position the new block into the required region and click ‘Save Blocks’
Hopefully, with this in place, you should now be able to see your tweets in full technicolor glory! There's an example down in the bottom corner of this page, albeit with some theming in place, alternatively to see a non-themed example have a look at http://www.moorfieldhouse.com (one of our sites and a very nice guest house in Scotland as well!)
Comments
Drupal twitter module
Hi I use the twitter module to tweet new content to my twitter account. It's a little hard to get up and running so I created a quick guide on getting it up and running.
http://www.drupaltutorial.co.uk/blog/setting-twitter-module-drupal-7
Hope it helps a few people out there. Thanks for your article helped, decided which way I wanted to use twitter on my website. :-)
beware special characters
Thanks! I found this very useful but also encountered an obnoxious bug that I wanted to apprise your readers of.
The title of my Twitter widget included an apostrophe. The Twitter code properly escaped this apostrophe:
title: 'let\'s escape apostrophes'
But somewhere in the block editing process, Drupal ate the backslash:
title: 'let's escape apostrophes'
The result being nonexecutable Javascript and a Drupal page that displayed my block title but no Twitter widget, and me beating my head against the wall.In short: these instructions are great. And if future readers find themselves wondering why they've followed them to the letter but the Twitter widget won't display, double-check your Drupal block to see if you need to stick a backslash back in...
Andromeda (andromeda@gluejar.com)
Thanks
Many thanks - good simple solution - much appreciated.
Cheers,
Steve
Drupal Version
Hi, thanks for the detailed tutorial. Unsuccessful in my implementation though, using Drupal 6.15. Tried fiddling with input formats, still no joy. What Drupal version are you using on this site?
I'm using Drupal 6.15
I'm using Drupal 6.15 currently (Jan 2010) so it's not that.
I use full HTML, but try it in PHP format if that doesn't work.
For debugging, try setting the block as a page and navigate directly to that page. You can also try grabbing the latest code from http://twitter.com/goodies/widget_profile as a base and placing that in a block.
I got it
I got it, YESSS!!!
What happened was I set width & height to auto, no block title, coupled with the fact (I suspect) that at the time I tested no data came in from twitter.com. The block then didn't show anything at all.
Now I even get to use not only my own twitter profile status feeds, but a list aggregated from those I was interested. Allow me to share how I did it.
First of all while logged in at twitter.com put each one you're interested into one single list, then code below. Btw I presume I'm using version 2 of the widget. Essential values to be changed are marked strong+em.
<script src="http://widgets.twimg.com/j/2/widget.js"></script>
<script>
new TWTR.Widget({
version: 2,
type: 'list',
rpp: 8,
interval: 8000,
title: 'Some Title',
subject: 'Some Subject',
width: 265,
height: 400,
theme: {
shell: {
background: '#BE1516',
color: '#ffffff'
},
tweets: {
background: '#000000',
color: '#ffffff',
links: '#4aed05'
}
},
features: {
scrollbar: true,
loop: false,
live: true,
hashtags: true,
timestamp: true,
avatars: true,
behavior: 'all'
}
}).render().setList('yourname', 'yourlistname').start();
</script>
Thanks again.
Edwin edcazini[dot]info
P.S. Try using TinyMCE's default CSS instead of your theme's in textareas, also I like (F)CKEditor best.
Thank you Simon and Edwin
Triffic
Tezza