How to Troubleshoot Apps for the Modern Connected Worker
ESWC 2014 Tutorial Handson 1: Collect Data from Twitter
1. Social Web: Where are the Semantics?
ESWC 2014
Miriam Fernández, Victor Rodríguez,
Andrés García-Silva, Oscar Corcho
Ontology Engineering Group, UPM, Spain
Knowledge Media Institute, The Open University
2. OAuth
• Twitter needs authentication
• Many SNS rely on OAuth to grant access to API features
• OAuth is a security protocol for Web applications.
– Security for REST and XML-RPC services.
– Signed HTTP Requests
– Safe, Password-less Token Exchange
• Actors: User / ServiceProvider / Consumer
ESWC 2014 Social Web: Where are the Semantics? 2
3. Twitter API
• General ideas
– Limit on the requests, in a per 15-min basis
– Each Tweet as an ID
– Objets: Tweets, Users, Entities (hashtags, photos, urls…), Places
• Capabilities
– Timelines (of user mentions, retweets, etc.)
– Tweets (given ID, retweet, etc.)
– Search (shown this in this tutorial)
– Friends & Followers, Direct Messages, Favourites, Trends….
– Places & Geo
– Users
– Streaming (the most powerful!)
ESWC 2014 Social Web: Where are the Semantics? 3
4. 1.- Obtain a Twitter account, register application
ESWC 2014 Social Web: Where are the Semantics? 4
1. Register a new Twitter account (or use yours)
2. Register as a developer: https://dev.twitter.com/
3. Register your new application
5. 2. – Obtain your credentials
4. See your API keys and generate a token
ESWC 2014 Social Web: Where are the Semantics? 5
6. To set up your project…you need two files
• TwitterDataCollector.java contains the code that you need to use
the Twitter REST API
• twitterCollector.properties. This is the properties file that you need
to set up. You need to add:
– consumerKey = (the data obtained in the step before)
– consumerSecret = (the data obtained in the step before)
– accessToken = (the data obtained in the step before)
– accessTokenSecret = (the data obtained in the step before)
ESWC 2014 Social Web: Where are the Semantics? 6
7. TwitterDataCollector
• You can find the code:
– In the code folder of the given USB
– https://gist.github.com/vroddon/9d5aac253afaa14c9471
• Open a command line window
• Test 1
– java -jar TwitterDataCollector.jar
– And you will have searched for tweets containing the word "#eswc2014"
• Test 2
– java -jar TwitterDataCollector.jar twitterCollector.properties #obama
– And you will have used the given properties file looking for the hashtag
#obama
• Output: a list of JSONs with Tweet info, one tweet per line
ESWC 2014 Social Web: Where are the Semantics? 7
8. Sample output
• Hint: use http://jsonviewer.stack.hu/ to see the JSON
ESWC 2014 Social Web: Where are the Semantics? 8