This is part two of three blogs on the use of twitter for research. Part one is here.
How Tags works (probably)
What I hope to do in this post is identify some of the moving parts that make Tags work. I will not try and delve into the actual workings of the code used as that is beyond my (hopefully current) abilities. What I will try and do instead is identify the different components which interact with each other to make Tags work. At the end of the post I will highlight some of the resources which I intend to use in gaining a better understanding of the inner workings of Tags. With a bit of luck I will be in a position to attempt to build something simple myself using what I’ve learnt.
The Nuts and Bolts
An API
The Twitter API is what allows access to the data of twitter. Having access to an API for twitter is required before we can think of developing methods of collecting Tweets. Once an API is set up and authorised we can start using other software to make use of the data in Twitter.
Google Apps Scripts
Google Apps Scripts is used to get data form Twitter, through the API, into a google spreadsheet. This script is what is going on behind the scenes when you ‘Run Tags’. It is these scripts which ‘talk’ to twitter in order to get our search, for example my search for #open access from my Google spreadsheet to twitter and back again with the appropriate tweets in tow.
Some computer languages
Google Apps Script makes use of Javascript – a common language used for web development. It is cloud based and many scripts can already be found which can be adapted for different purposes.
HTML – is used to make the TAGS website itself. HTML is a fairly accessible language and since it’s primary purpose is formatting text for websites, the logic we need to approach it with isn’t so unfamiliar to us.
Alongside this are a whole host of other languages which are running in the background. The purpose of this post isn’t to be exhaustive but to try and give myself a better understanding of some aspects of coding I may want to pursue.
Scary gobbledegook!
Before highlighting some of the resources available for learning more about this coding business I decided to have a look at a little bit of code myself and see if I could make any sense of it. This is a bit of code which updates tags so it works with the new version of Twitter’s API. You can have a look at the code on Github.
There is a lot I don’t understand about the inner workings and syntax of the code but hopefully I can point out some of the general principles. This is largely an exercise in trying to convince myself (and with a bit of luck you!) that this coding business is not beyond comprehension.
I have cut some snippets of the code and will summarise what I think each bit is roughly about. It is quite possible I am completely of the mark (feel free to tell me if this is the case).
function getTweets(searchTerm, maxResults, sinceid, languageCode) {
//Based on Mikael Thuneberg getTweets - mod by mhawksey to convert to json
// if you include setRowsData this can be used to output chosen entries
This is a description of what the purpose of the code is.
var data = [];
var idx = 0;
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sumSheet = ss.getSheetByName("Readme/Settings");
if (isConfigured()){
var oauthConfig = UrlFetchApp.addOAuthService("twitter");
oauthConfig.setAccessTokenUrl("https://api.twitter.com/oauth/access_token");
oauthConfig.setRequestTokenUrl("https://api.twitter.com/oauth/request_token");
oauthConfig.setAuthorizationUrl("https://api.twitter.com/oauth/authorize");
oauthConfig.setConsumerKey(getConsumerKey());
oauthConfig.setConsumerSecret(getConsumerSecret());
var requestData = {
"oAuthServiceName": "twitter",
"oAuthUseToken": "always"
};
} else {
Browser.msgBox("Twitter API Configuration Required")
}
Code is often written with a similar basic logic (it does get more complicated of course). This logic often goes along the lines of: trying doing something, if that doesn’t work do this other thing. This section of code is I think trying to establish a link between the spreadsheet and twitters API. The ‘if’ is trying to get the Oauth access token.[1] The ‘else’ tells the programme what to do if the API hasn’t been authorised. It will display a message saying ‘Twitter API Configuration Required’.
The rest of the code starts to make less intuitive sense to me. I will try to understand what this means at some point!
Resources
Here is a small list of resources which I intend to pursue. They are in a somewhat rough order based on the criteria of what I think will be both most accessible and immediately useful to me (and maybe more generally for non computer expert librarians).
HTML and CSS
HTML is probably one of the most accessible languages to get a basic grip on. I already have some experience with HTML and LaTeX[2] which is fairly similar. I don’t have any experience with CSS but it is included with many of the HTML tutorials and since it is a big part of styling websites it makes sense to try to learn this alongside HTML.
- Code Academy
- W3schools
- http://learn.shayhowe.com/html-css/
There are plenty of other sites available and many free resources so it is probably best to just try them out and see what you like.
Google Apps Scripts/Javascript
Since Tags works using Google Apps scripts I am intrigued to explore how this works. Google provides some introductions and tutorials on their site. Google scripts works on the basis of Javascript and it is another language heavily used on the web so I think it makes sense to explore this a little bit.
- Google Apps Scripts
- Code Academy Javascript
Ruby
Another language commonly used on the web. I have often heard it described as a very ‘elegant’ coding language. Might as well learn a bit of an ‘elegant’ language alongside a more ‘ugly’ language like Javascript! There also seems to be lots of good resources for this so it is definitely on my to do list.
http://tryruby.org/
This is a fun website that gives you a chance to try some basic coding using Ruby.
- Google Apps Scripts
- Try Ruby
- Introduction to Ruby comic!
There is quite a lot to get on with here. Whether I find time to really ‘learn’ any of these languages fully during the rest of the DITA language is doubtful but I do hope to make a start and see how I get on. If anyone has any tips feel free to drop a comment below!
[1] This was discussed briefly in the DITA lecture. It is is essentially an open standard for ensuring secure authorisation of different applications. There site is here http://oauth.net/
[2] LaTeX is a ‘document preparation system’. It can be used instead of a ‘what you see is what you get’ (WYSIWYG) programme like Word or LibreOffice to prepare text documents. Instead of formatting everything by hand as you do with Word or LibreOffice you indicate the structure with some syntax and LaTeX ‘typesets’ the document for you. It tends to produce much more attractive documents then WYSIWYG programmes and is pretty easy to use once you have got a hang of the logic behind it.