logo

Using Twitter Data for
Research

Issues of Data Retrieval, Management, and Processing

Rob Chew , Annice Kim , Paul Ruddle , Clay Heaton

RTI International

The Social Media Landscape

Opinion has never been this cheap, timely, or abundant

  • Harder to acquire data from traditional survey methods
    • falling response rates
    • inadequate sample frames
  • Huge opportunity for survey researchers to harness insight with social media

Twitter Data Access

Three main ways to get Twitter data:

Social Media Monitoring

(Radian6, Crimson Hexagon, etc.)

Twitter Authorized Resellers

(GNIP, Datasift)

Twitter API

Twitter API: REST vs. Streaming

  • REST API - To get information, user must specifically request it
    • Well over 50 different REST API "Resources"
  • Streaming API - Once request is made, provides continuous stream of updates without further input from user (up to 1% full twitter stream)
    • Has "Public", "User", and "Site" streams

Twitter Data

Connecting to Data

  • First, need authentication to connect to Twitter (OAuth)
  • Next, need a general purpose programming language to talk with both the API and your database
    • Ex: Python, PHP, JavaScript/Node, Ruby
  • Many libraries available to ease in connecting to the API
  • Likewise, you’ll need a library to connect to your database
    • Ex: PyMongo, to integrate with MongoDB

Twitter Data Storage

  • Data stored as JSON (JavaScript Object Notation)
    • Key-Value pair
    • Allows for nesting of fields and is flexible
    • 
      {u'_id': ObjectId('53d11ddd28975720fa77c8aa'),
       u'contributors': None,
       u'coordinates': None,
       u'created_at': u'Thu Jul 24 14:10:49 +0000 2014',
       u'favorite_count': 2,
       u'favorited': False,
       u'geo': None,
       u'id': 492310941657481216L,
       u'id_str': u'492310941657481216',	
       u'lang': u'en',
       u'place': None,
       u'retweet_count': 0,
       u'retweeted': False,
       u'text': u'i need to doze off before i doze off \n\U0001f634\U0001f634',
       u'truncated': False}
          
  • Based on tweet data structure and volume, NoSQL databases are a great storage solution
  • Due to the learning curve, other output types might be more practical (ex: csv files)

NoSQL example: MongoDB

  • Document-Oriented Storage
  • Index Support
  • Straightforward Queries
  • Speed

Analysis

Complications!

Conclusion

  • Although collecting, storing, and analyzing Twitter data can be complicated, surveys are also complicated and labor intensive
  • Twitter data is not perfect - for instance, Twitter may decide to pull the plug on the public API, leaving everybody in a lurch.
  • Nonetheless, with the continuing trend of falling response rates and inadequate sampling frames, getting cheap and timely data without burdening respondents is an enticing proposition.


Questions? Feel free to reach out to rchew@rti.org