Setup for #altc 2014

This post is for my own reference but others may find useful. The information below is the result of drawing on the expertise of Darren Moon (LSE) for some of our ALT live events.

ALT has a YouTube channel - for any channel that has more than 100 subscribers* that is ‘good standing’ YouTube gives the option to be able to stream live events. With this you create an event on YouTube in your channel which people can view there or embedded in another site (as you would embed Youtube videos). A nice feature of Live Events is they are immediately available for playback as well as being streamed live. 

*thanks to Steve Boneham for the correction

To stream the event you need some software. Google have a deal with Telecast to provide their Wirecast software for free (stripped down version). The software allows you to connect cameras and other inputs (you need to have equipment that supports a live video feed. Firewire was the way this was mostly done but now it's moving to HDMI input - to get HDMI into our laptop we used these magic boxes). The Wirecast software also allows you to do a live production with indents and different camera shots. For belt and braces the software also has the option to record your mix to your hard disk in case the stream is lost (we also record the raw footage on the camera in case Wirecast falls over).

[Wirecast can also output to a Google Hangout OnAir if you don't have a YouTube Channel - we haven't made use of this though] 

The usual headache doing this is (particularly as we do this on the road):

  • internet access (wired preferred) - we've never had an issue with (ports) configuration but something we always check
  • audio source - if using wireless mics getting the feed is something we ask for. In smaller events placing a boundary mic and getting the cable to the camera/laptop requires very long wires
  • desktop mirror - the best way to include slides is to mirror what is being thrown to the data projector. When this isn't available we either have a second camera on the main screen or another laptop running the presentation
  • space - you need space for at least one laptop and camera. We monitor the feed and back channel so often have 2-3 extra laptops doing different things
  • people - you need at least one person to do all of this, we usually pair up
  • power - less of an issue for sort events when you can run from batteries

There's lots of info on how to do this sort of thing online with recommended kit lists, alternative live streaming services. ALT has the Video in Education SIG (ViTAL SIG) which would be a good place to go for advice

It’s been a while since I've had a chance to blog about a failed attempt to do something. Recently I was trying to get full screen access in Google Drive using Google Apps Script and I couldn't get it to work resulting in this feature request (star to vote ;). In this post I want to share some of my thought processes and highlight why this would be a useful feature.

In the middle…

One of the nice features of Apps Script is access to custom dialogs and interfaces in Docs, Sheets and Forms. These can be generated using the HtmlService, which enables you to write very rich and interactive interfaces. Until very recently all the Html you created went through Google’s Caja Compilier. Caja created a lot of headaches for Apps Script developers striping and reformatting html tags and restricting what you could do. For example you could forget using SVG (scalable vector graphics) making it impossible to use well established visualisation libraries like D3.js.

Román Cortés 1kb Christmas Tree in Apps ScriptHowever, in December the Google App Script team announced Speeding up HtmlService with the IFRAME sandbox mode. With this there is now the option to skip Caja sanitisation and a whole host of modern browser-based application deployment. For example here’s  Román Cortés 1kb Christmas Tree in Apps Script (I've tipped it over the 1k mark as it was throwing an error in Chrome. - the source code for this project is here). Huh turns out with blocks can't be used anonymously, as script owner this works fine :(

The IFRAME mode should not be confused with the ability to use <iframe> to embed your published scripts. This isn't currently possible for security reasons and there is an issue ticket for it.

In the beginning…

My interest in using custom visualisations in Google Sheets stems back to 2011, my first attempt wrapping Protovis SVG graphs, the precursor to D3.js, as a Google Spreadsheet Gadget. Alas Spreadsheet Gadgets got deprecated in the ‘spring clean of 2012’. One of the big advantages of Spreadsheet Gadgets was you didn’t have to publish the data to be able to generate a visualisation, (a route I use for my TAGSExplorer tool). Unfortunately I don’t have a screen shot of how the Protovis Gadget rendered so you’ll have to make do with a later version which switched to D3.js:

Google Spreadsheet Gadget Example

With the new IFRAME  mode there is an opportunity to re-explore how custom visualisations and analytical tools could be integrated in Sheets as well as Docs and Forms. Bruce Macpherson has already shown an example of D3.js in the Sheet sidebar:

CC-BY-SA brucemcpherson
CC-BY-SA Bruce Mcpherson - D3.js in the Sheet sidebar

With this we've come almost full-circle with the ability to create custom visualisations around data in Google Drive without the need to publish it. One limitation here is the amount of screen space you can play with. Sidebars are restricted to 300px wide. You can use dialog windows but these would have to be a fixed size and as far as I'm aware there are no browser detection methods for factor in the available screen size. But lets not forget that I'm predominately talking about scalable vector graphics here and most modern browsers now support the Fullscreen API (Fullscreen API spec). To see this in action embedded below is an iframe of this page, which if supported by your browser, will let you to pop it to fullscreen using the button (I'm just using a raster image to keep with the Xmas theme ;).

So using Apps Script we could have fixed size interfaces with the ability to stay in Docs, Sheets or Forms interface but pop to fullscreen … Well as you have probably already noticed from the post title nope. Here’s a Sheet where I’ve used the same full screen code in a custom dialog. Clicking the ‘Image Test’ link in the spreadsheet opens the dialog but while the fullscreen script runs nothing happens. Initially I thought it was something wrong with my code but trying a YouTube embed within a custom dialog resulted in now full screen option being included.

YoutTube Embed - no full screen

In the future…

Having access to Fullscreen API would be one way to get us back to 2011 and there may be other feature requests around embedding custom interactive graphs in Google Drive. If you’d like access to the Fullscreen API in HtmlService here’s the feature request.

Oh and happy holidays ;)

4 Comments

Having a domain of your own is a wonderful thing but like many things in life it comes with responsibilities. Self-hosted WordPress blogs are a regular focus of spammers and brute force attacks and more than likely your webhost already has measures in place to prevent the bots getting in. There are proactive measures you can also take to protect your domain and a host of plugins and tutorials to help with this.

To add to the collection I want to share with you my experiences of setting up and using CloudFlare. CloudFlare creates an extra layer between your website and the world allowing them to block threats as well as host and optimise your content. At an entry-level you can also use CloudFlare for free, which I've been doing for the last couple of months.

httpsRecently CloudFlare announced they were Introducing Universal SSL for all users for free. SSL/TLS are encryption protocols used to secure Internet communication. Hopefully you are familiar to looking for the https:// and not just http:// when you are doing your online banking or online shopping, the ‘s’ indicating the information you see and enter is secure, encrypted, preventing eavesdropping or tampering of the data. But why would I want to use a similar level of security for my blog as for banking? CloudFlare make a great case for this in their post:

Having cutting-edge encryption may not seem important to a small blog, but it is critical to advancing the encrypted-by-default future of the Internet. Every byte, however seemingly mundane, that flows encrypted across the Internet makes it more difficult for those who wish to intercept, throttle, or censor the web. In other words, ensuring your personal blog is available over HTTPS makes it more likely that a human rights organization or social media service or independent journalist will be accessible around the world.

[Another consideration is Google announced it would use https as a rank factor in it’s search results]

So how do you go about moving your blog to https? Well first, if not already, you need to sign up and setup CloudFlare. There are two routes to do this provided by CloudFlare. Unfortunately my host, Reclaim Hosting, isn’t yet so I had to go through changing nameserver settings (CloudFlare have additional tips on using their service with WordPress). When CloudFlare is set up, to switch enable SSL you need to go into the CloudFlare Settings > Setting overview where you see the SSL configuration:

SSL settings

CloudFlare SSL OptionsCloudFlare actually have a couple of options: Off, Flexible SSL, Full SSL, and Full SSL (Strict). Flexible is by far the easiest to set up and for most people the best place to start. There is a lot more detail about the difference between these in this CloudFlare post. In this they say:

Flexible SSL encrypts all data between your site’s visitors and CloudFlare using TLS configured with best practices such as forward secrecy and more. This is where most threats to web traffic happen: in your coffee shop, by your ISP, and others in the local network.

With this enabled and directing traffic through CloudFlare you can start using https on your blog. There are a couple of things to bear in mind as well as things you have to do. To use https effectively you need to tell your blog this is what you want to use.  There are plugins like WordPress HTTPS (SSL) that can help with some of this but I decided to do it the manual way.

Dashboard and site over SSL

Initially when I tried switching to SSL I ended in an endless redirection loop. Fortunately I came across this post on how to  Setup SSL on WordPress Behind Cloudflare Reverse Proxy. This is backed up by the WordPress documentation on Administration Over SSL and you might want to start with using the first 3 lines of code in your wp-config.php file to test that SSL is working:

define('FORCE_SSL_ADMIN', true);
if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
       $_SERVER['HTTPS']='on'; 
define('WP_HOME','https://yoursite.com');
define('WP_SITEURL','https://yoursite.com');

When switching to SSL you may find parts of you posts don’t load. Some of this is down to how your theme has been written and for good themes it shouldn't be a problem. The next problem might be missing videos or images in posts. Basically modern browsers don’t like mixing http with https content. So if you use iframes as a way to embed content like YouTube videos and they are loaded over http nothing will appear. Google updated the embed snippet for YouTube videos from <iframe src=http://www.youtube… > to <iframe src=//www.youtube… > which defaults to serving the content using the same method as the main page. You can run MySQL commands to update these or it might be better to use one of the WordPress SSL rewrite plugins.

Forcing to SSL

So far we've enabled the option for your blog to be browsed over SSL including internal navigation links, but some one still might initially land on an http address. CloudFlare mention Page Rules in their admin interface for forcing to SSL but that setting appears to have disappeared. CloudFlare also mention a way that Apache hosted blogs can use the .htaccess file to redirect a user on to SSL:

 RewriteCond %{HTTP:CF-Visitor} !'"scheme":"http"'
 RewriteRule ^(.*)$ https://www.domain.com/$1 [L]

If like me you still use FeedBurner (I know) for your RSS feed you should also bear in mind that you need to keep your feeds alive for Feedburner (avoiding 400 error) – basically Feedburner doesn’t like to be given feeds over SSL. So my snippet for .htaccess becomes:

# HTTPS redirect
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_USER_AGENT} !FeedBurner    [NC]
RewriteCond %{HTTP_USER_AGENT} !FeedValidator [NC]
RewriteCond %{HTTP:CF-Visitor} !'"scheme":"http"'
RewriteRule ^(.*)$ https://yoursite.com/$1 [L]

Remember if you are forcing to SSL that any tools/apps you use connected to your blog like Live Writer might need updating .. as I discovered

Letting Google know you've moved

The last thing I did was let Google Search know my blog was now over SSL. You may have plugins that handle your sitemap and updates to search engines. For me I did this using Google guide on Move a Site with Url changes.

Future

So a bit of work to get myself on SSL and save a couple of bucks on a SSL certificate. The good news is this sort of thing is hopefully going to get easier and more widespread

More Library Mashups (Cover)I've a couple of book contributions in the bag notably Into the wild – Technology for open educational resources and the Analytics for Education chapter in Reusing Open Resources. My latest output is my first solo effort in More Library Mashups, edited by Nicole C. Engard. The chapter, 'OpenRefine(ing) and visualizing library data', is a work up of one of the posts I released as part of the UKOER Visualisation Project on extracting and visualising repository data from Jorum. The chapter again revisits Jorum as a data source. The abstract goes:

Visualizations are a powerful way for people to explore and analyse data. Libraries, by their nature, have access to a generate substantial amounts of data. Even with the best of intentions library data can be messy. Whilst we can apply structural frameworks like cataloging rules, subject classifications and controlled vocabularies at some point the machine world is interfaced by humans. ‘Messy data’ was the challenge faced by Metaweb Technologies, Inc. who in 2007 announced the launch of Freebase (www.freebase.com), a community project designed to create "an open shared database of the world's knowledge". As part of this Metaweb created Gridworks, an open source desktop tool designed to help in cleaning messy data. Now called OpenRefine, we look at how this tool can be used to show how the history of repository deposits can be visualized as ‘code swarms’.

Copies of More Library Mashups can be preordered here

1 Comment

+Tom Smith kindly reminded me that there are existing Google Form Add-ons to achieve a similar result without having to mess with code. So you might want to have a look at Choice Eliminator by Bjorn Behrendt and formLimiter by Andrew Stillman

You can imagine the scenario, you’ve got a Google Form perhaps setup as a booking form and a select option for picking timeslots. As the slots fill up you’d like the option to be removed. I was surprised not to find an example of this so here is a rough sketch of some code that might do the job. We start with a basic form with a ‘choose from list’ option:

Select option

and in the linked Google Sheet we have an extra sheet to keep tally:

tally

In this sheet I’ve got a column with quotas for each of my select options and a calculation for how many are left =B2-COUNTIF(responses!B:B,"="&A2)

To dynamically modify the Google Form we need to add some code. Here’s a basic snippet that reads our options and quotas and rewrites the select options (note the inline comments for bits you’ll need to edit):

function availableSlots(){
  var form = FormApp.openByUrl('URL_OF_YOUR_FORM'); // TODO add your form url
  // need to read what slots are available
  var slots = SpreadsheetApp
                .getActiveSpreadsheet()
                .getRange("slots!A2:C10")
                .getValues(); // TODO make sure getRange matches your quota range
  var choice = [];
  // loop through our available slots
  for (s in slots){
    // test if slot still available
    if (slots[s][0] != "" && slots[s][2] > 0){ 
      choice.push(slots[s][0]); // if so we add to temp array
    }
  }
  var formItems = form.getItems(FormApp.ItemType.LIST); // our form list items
  // TODO assumption that first select list is the one you want to change  
  // change formItems[n] if you have more than one select list
  // and we just rewrite all the options to ones that are free
  formItems[0].asListItem().setChoiceValues(choice); 
}

To enable this you need to use the Tools > Script editor in you Google Sheet and then Resources > Current project’s triggers. At this point to may be prompted for authorisation to read the data and change the form. Once that’s done add the availableSlots function to trigger on form submit.

Current project’s triggers

If you’d like to shortcut all but this last step make a copy of this template.

Notes

Some things to be aware of. If you have concurrent users submitting the form someone may sneak in. Apps Script has ways of preventing this but not as far as I’m aware for Google Forms. It’s worth remembering that do don’t need to use Google Forms at all for getting data into a Google Sheet and if you can host your own HTML form you can make POST/GET requests. If you develop this example further I’d be interested to hear about it. Enjoy!

1 Comment

In the Apps Script G+ Community Scott Marquardt asked:

Youtube API question.

Argh, I can't find a single example of anything like this. With my current knowledge, I have a hard time inferring from the API reference documents alone, to Apps Script.

My goal is a script to add an item to a Youtube playlist.  My intended workflow is a Google form to enter video IDs into a Google sheet, with a triggered script adding each new video ID to a hard-coded playlist.

I'm unashamedly panhandling here, on behalf of what would be a really valuable use case in a dozen of our special education schools.

I agree with Scott that the Apps Script Advanced Services documents (here’s YouTube) don’t give you much to go on. The solution is actually relatively simple once you get your head around the shape of the data required. So here is a form linked to this playlist (I’ll turn this off as soon as it starts  getting spammed). In the spreadsheet receiving responses the Tools > Script editor has the following code (in the script you’ll see where you need to hard code the playlist you want to add videos to):

Update: Scott asked about adding notes/comments to playlist items and I've updated the code to do this to the gist

To get this working there are a couple of hoops to jump through. As the YouTube API is an Advanced Service and it must be enabled before use. For this project to do this you need to be in the Script Editor then:

  1. Click Resources > Advanced Google Services…
  2. Scroll down to YouTube Data API to turn it on then click the ‘Google Developers Console link:
    Enabling Advanced Services
  3. In the Google Developers Console find and turn on the YouTube API. After it’s enabled you can close the Console window

You can only interact with YouTube Channels the account authorised to run the script is the owner of (see related post by me on this).

The final step is to setup the script to trigger when the form is submitted. To do this while still in the Script Editor  select Resources > Current project’s triggers and add a run addVideoToPlaylist event on form submit.

Current project triggers

If you would prefer to not do all the code copy and pasting you can File > Make a copy of this sheet (you’ll still need to enable Advanced Services and the form submit.

There’s obviously lots more you could do with this script like putting submissions into a moderation queue but I’ll let you go and play with those ideas.

2 Comments

I was recently invited to London to talk at the GDG DevFest London. The idea for my talk was:

With a pre authenticated cloud-based ecosystem Google Apps Script makes it possible to integrate into other Google services with a couple of lines of code. This turns Google Drive into a rich playground for custom reporting using Google Sheets as a data interface. In this session there will be a quick Google Apps Script 101 highlighting some of it’s main features and affordances. This will be followed by a demonstration of how Google Apps Script makes it easy to combine Google Analytics with other data sources such as Twitter and do many more playful things.

As part of this I highlighted 3 features of Apps Script I find particularly powerful. These were:

  1. Custom UI – creating dialogs and interfaces integrated into Google Docs, Sheets and Forms.
  2. Triggers (in particular timed and POST/GET) – there are a number of different triggers you can use in Google Apps Script but the ones I lean on the most are timed triggers and open scripts to POST/GET requests. Timed triggers let you run scripts on intervals even when you are not at the keyboard. The particular power of publishing a script to handle POST/GET requests that I like is that the script can run as you of the person accessing the script. Build in features also let you restrict access so that the script can only be run by you, someone on your domain, anyone and anyone even anonymously.
  3. Integration – there is some overlap with the previous two but given the potential worthy of note.  In other platforms developers it’s sometimes necessary to do a lot to setup the platform and prepare it for other people to use. Apps Script comes already  integrated with a number of Google products which means in a couple of lines of code you can access other services. As a demonstration you can see below that with Apps Script in one of line of code you can get a persons unread email count … plus a bunch of other Gmail data.

    GDEGmailMid

For what it’s worth slides embedded below:

You’ll find lots of blog posts explaining how to do this the other way, converting a table from Wikipedia into a spreadsheet. I even cover this myself in Feeding Google Spreadsheets: Exercises in using importHTML. This post looks at taking a .csv or a spreadsheet and formatting it as a Wikipedia table.

I’ve been on a bit of a Wikipedia journey expertly guided by a friend, Simon Knight (@sjgknight) … who happens to be Wikimedia UK Vice Chair. The journey has included Wiki ShootMe which has been covered by Alan Levine (@cogdog) and a wonderful Teaching Wikipedia Editing session you can still watch from Connected Courses.

One of the great things about Wikipedia is there is no shortage of information on how to do stuff. Before jumping in I had a quick look for some existing tools and came across this article on Importing (converting) content to Wikipedia (MediaWiki) format. Listed is the Spreadsheet-to-MediaWiki-table-Converter. This is some code you would more normally run on a server possibly used as a library within another project. Wanting something simpler I looked for and found guidance on creating a sortable table. The guidance helpfully includes an example copied below:

{| class="wikitable sortable"
|-
! name
! data
! more data
|-
| cats
| 273
| 53
|-
| dogs
| 65
| 8,492
|-
| mice
| 1,649
| 548
|}

And here is what it looks like:

namedatamore data
cats27353
dogs658,492
mice1,649548

Hopefully you can quickly see the pattern, you start with the column headings, one per line of wikicode and then each of the rows again one value per row for each cell. This type of pattern is easy to code … if you can code … … if you want to code. As I was composing my first line I remembered an old project Templated Export for Google Spreadsheets:

Templated Export allows users to reshape and selectively publish data from Google Spreadsheets in custom formats. The tool is powered by Google App Script which allows integration with Google Spreadsheets using existing authenticated access. Example uses include: turning data from a spreadsheet into a RSS feed and publishing data from a spreadsheet in JSON format to be used by other tools/services. The framework for creating a custom wrapper for your data means there are many more opportunities.

Templated Export lets you customise use a basic reference system to create you own output pattern:

Templated Export

There is some learning curve using this and original post has details on setting this up and using it. The basic concept is you use a cell reference as a way to build up your pattern. You can save your templates which means if you update your data in your Google Sheet you can open the Templated Export interface and download it again or use a saved ‘published url’.

Templated Export hasn’t been touched for two years and is perhaps a candidate for some ‘modern’ Google Apps Script techniques such as publishing as an Add-on. If the thought of playing with Google Apps Script doesn’t take you fancy, Templated Export is based on a feature of OpenRefine called Templating Exporter. OpenRefine can be downloaded and run from your desktop and can handle a variety of data file formats.

So go forth and fill Wikipedia with lovely tables for everyone else to reference in ‘Wikipedia table export’ posts ;)

1 Comment

I previously posted about TwtrService: A Twitter API client library for Google Apps Script which makes it easy to interact with Twitter from Google Drive applications like Google Sheets. One of the nice things about TwtrService is that once you setup a connection to Twitter you can use it many times in different projects, basically allowing you to do stuff in one line of code. In the post I said I’d share some of the examples of things I make so here is the first one, EasyTweetSheet.

What it does

At the Association for Learning Technology we organise lots of events. We only have a small staff team so having someone sending out tweets during the event can be a problem. We could use a Twitter client like Tweetdeck or Hootsuite  to schedule tweets during the day. One issue is if something goes wrong like the livestream not working or a session starting late you can look a bit silly. The solution was to draft our tweets in a Google Sheet and have a link we click when we want the message to be sent. Below is a screenshot for the one we used at this year’s ALT Annual Conference:

EasyTweetSheet used at #altc 2014

How to get you own copy working

  1. Open this copy of the EasyTweetSheet templateand File > Make a copy
  2. In your copy open Tools > Script editor and follow the instructions
  3. Start filling the ‘text’ column with what you want to tweet which should enable the ‘tweet’ link

IMPORANT: If you’ve used my other tools like TAGS this template will use the Twitter account you used to set it up. To use a different Twitter account to send the tweets from
replace YOUR_CONSUMER_KEY and YOUR_CONSUMER_SECRET in lines 34-35 of the Script editor code with your Twitter application key/secret. When you Run > setup switch back to the Sheet view and follow the instructions.

Enjoy!

3 Comments

As part of the latest release of TAGS (Twitter Archiving Google Sheet) I moved a lot of the code into a Google Apps Script Library. Libraries are a great way to bundle and release code allowing you to write your own classes and methods. To see some of the functionality already being developed by the Apps Script community you should have a look at the Google Apps Script Samples site and the excellent work Bruce McPherson has done which includes a EzyOauth2 library.

One of the things you can do with libraries is wrap one library into another. When rewriting TAGS it made sense to strip out a separate Twitter client library that I and others could use in different projects. Based on the work by Arun Nagarajan at Google, TwtrService provides  access to Twitter's REST API. The work I’ve done is to add some UI and configuration methods to try to streamline the authentication flow. As part of this developers can offer authentication routes using their own Twitter application or use an application created by users. This particular angle is a result of one of the design principles for TAGS, that every copy of the template should use a Twitter application owned by the user. The reason behind this is to distribute the risk. If Twitter were to suspend my data access because a TAGS user abused their API it would suspend access for all TAGS users. By requiring TAGS users to register their own application with Twitter the responsibility to abide by Twitter’s terms of service lies with them. So in TAGS the auth flow looks like this

The result is hopefully a flexible library that developers can integrate into their own projects or by getting users to register their own.

Over the next couple of weeks I'll be sharing some examples applications we've developed at ALT. In the meantime this post serves as a basic introduction to TwtrService and covers:

Overview of TwtrService

The TwtrService library for Google Apps Script centrally stores your Twitter access details allowing them to accessed from multiple script projects without the need for re-authentication. TwtrService is designed to allow you to directly use the Twitter’s v1.1 REST API GET and POST methods. For example to return Twitter search results for the search ‘Google Apps Script’ you would use:

var data = TwtrService.get('https://api.twitter.com/1.1/search/tweets.json', {q: 'Google Apps Script'});

The url string can also be abbreviated to:

var data = TwtrService.get('search/tweets', {q: 'Google Apps Script'});

Additional options can be passed in the parameters array. For example to return 100 results for the same search you would use:

var data = TwtrService.get('search/tweets', {q: 'Google Apps Script', count: 100});

The project key for this library is MarIlVOhstkJA6QjPgCWAHIq9hSqx7jwh and the TwtrService methods are documented here.

To use the Twitter REST methods TwtrService first needs authenticated access. TwtrService has some built-in methods to do this detailed below. Once a user has authenticated access the TwtrService library stores these as User Properties. This means when a user has authenticated once with TwtrService using the library in another container-bound or standalone Apps Script immediately gives them access to Twitter API results using the get/post methods. In terms of security User Properties are limited to the effective user of the current script.

Usage

Quick start: Personal access

If you would just like to use TwtrService for your Apps Script projects the easiest way to get started is to register a Twitter application and enter it’s details on this page (if you are interested here is the source code for the interface).

Note: If you are already a user of TAGS you’ll already be able to use TwtrService without the step above.

In your Apps Script project you’d like to use the Twitter API in the Script Editor window use Resources > Libraries and add the service  using the project key MarIlVOhstkJA6QjPgCWAHIq9hSqx7jwh.

In your project you can now use the TwtrService.get() and TwtrService.post() methods. The documentation for get() is detailed below (post is the same but uses HTTP POST):

get(string url, Object parameters)

GET wrapper for request to the Twitter REST API. For full documentation of API method endpoints and parameters see https://dev.twitter.com/rest/public. For example to get last 100 tweets containing 'Google Apps Script': var data = TwtrService.get('search/tweets', {q: 'Google Apps Script', count: 100});

Arguments:
NameTypeDescription
urlstringTwitter REST API resource url. This can be either long form e.g. https://api.twitter.com/1.1/search/tweets.json or abbreviated e.g. search/tweets
parametersObjectadditional API parameters as detailed in the Twitter REST API documentation e.g. for search results a search string and count is specified by {q: 'Google Apps Script', count: 100}.
Return Values:
TypeDescription
ObjectAPI response in JSON format.

Quick start: Personal access in Sheets and Documents

If you would like to replicate the TAGS authentication flow where users enter their Twitter application key/secret TwtrService comes with a number of UI methods. For TAGS the following code is used:

/**
* Launches key/secret and auth flow
*/
function setup() {
  if (TwtrService.isUserConnectedToTwitter()){
   var result = Browser.msgBox("Twitter Authorisation", 
                   "You appear to already be connected to Twitter.\\n\\nWould you like to run the setup again?", 
                   Browser.Buttons.YES_NO);
    // Process the user's response.
    if (result == 'yes') {
      // User clicked "Yes".
      TwtrService.showTwitterKeySecret(SpreadsheetApp);
    } 
  } else {
    TwtrService.showTwitterKeySecret(SpreadsheetApp);
  }
}

/**
* Used as part of setup() to process form data
*/
function processForm(formObject) {
  TwtrService.setUserKeySecret(formObject);
  TwtrService.showTwitterLogin(SpreadsheetApp);
}

Quick Start: Shared Twitter Key/Secret

The earlier examples have assumed the user registers their own Twitter application. For scenarios where you would like to have the option for users to have authenticated access using a dedicated Twitter API key/secret it is possible to initialize these values. An example application code can be found here which is also deployed here.

Similar to earlier examples once a user authenticates access with your key/secret as long as these values are also initialized in other script projects the user will have access to the Twitter API via TwtrService.

Instructions for creating a Twitter Application to use with TwtrService

TwtrService requires you to have a registered Twitter application. If you are If you haven’t already done this here are some steps you need to get started:

  1. Register for an API key with Twitter at https://dev.twitter.com/apps/new (if you've already registered for a TAGS sheet you can reuse your existing API Key and Secret).
    • Name, description and website can be anything you like
    • Important Include the Callback URL https://script.google.com/macros/
  2. Read the 'Developer Rules of the Road' before clicking 'Create your Twitter application'

On the Twitter site your application should include a ‘Keys and Access Tokens’ tab which includes the Consumer Key (API Key) and Consumer Secret (API Secret) you’ll need.