Apps Script‎ > ‎

Tweet Button

        Working with Google Sites can be frustrating, since it blocks scripts that originate from external sources. If that's just jibberish, what it means is that when you want to include something cool from social media (Twitter, Facebook, even Google Plus), it's really hard because all the interaction is created by those sites, and not your Google Sites page. I recently wrote a small bit of Apps Script to add a "Tweet" button to Google Sites, and in my usual manner, I took it much, much farther than I ought, just to get it working the way
I think it should. Keep in mind, there are still some things I'd like to fix (that annoying white box in the background, for one), but I wanted to post it as is.

        It was originally run as an Apps Script file attached to my site. It looked good, worked well, and everything was hunky-dory, or so I thought. Then a friend reached out and mentioned that there was this horrid, ugly warning at the top of the small space where the button should appear, warning him that the script was not written by Google. AAAAAAAARRRGH! was my thought process at that moment. I knew then that I had to end up writing it as a Google Sites gadget itself.

        I did a short write-up in the Sites Tips 'n' Hacks section of this site, and you can check out the basic version there. In this page, I've posted the source code of how I got it to work, finally, without the warning text.

        If you just want to use it, and don't care how it works, here are the tl;dr steps:
  1. Edit your sites page, click on insert - gadgets - more gadgets...
  2. Choose "Add gadget by URL"
  3. Paste in this url - http://www.opensourceteacher.ca/Tweet_Button.xml

What it Does

  • This gadget adds a "Tweet" button to a Google Sites page, with a link back to the page from which it was clicked. Actually, any sites page on your website - they can all use the same script and it will pull the page from which the action was initiated, and include that link.
  • Create a suggested tweet, including content, URL, and hashtag (which you can customize).
  • Add you as the origin of the tweet with a "via @YourTwitterHandle" annotation.

Source Code

The gadget spec URL could not be found