This is the first part of a two-part vignette demonstrate the use of the Twitter Search API collection and analysis functionality of the twinfoR package. One use of Twitter analyses is to investigate what is going on in different locations. A simple way to collect Tweets related to a location is to use the Twitter Search API, searching on the hashtag containing the location name. Of course, this introduces a bias into the analysis, but can still be useful.
In this Vignette, we’ll look at two locations: Boston and Guatemala City. We’ll use the following hashtags:
Let’s start by importing the twinfoR namespace. Don’t forget to install the package, if you haven’t already.
We’ll be using the query_text table functionality of the twitter_database. See twitter_database documentation for details. We begin by creating the query_text table containing our search queries.
We need to set a working directory to store the database and analysis products. Once we set the directory, we’ll change into it and initialize the location database with our query.text.dataframe. Note that this vignette does not use the query_users table, but it could. See the US Politics vignette and the twitter_database documentation for examples on how to include and use a query_users table.
We’ll use the INFORM-Tutorial Twitter Application. Alternatively, you can supply your own application credentials using the authorize_app function.
You will need a Twitter Account to continue! If you don’t have one, you can easily create one on the Twitter website. If you do not have a Twitter account and do not wish to make one, this package will be of very limited use to you.
I recommend logging onto Twitter in your Browser before running this line. Either way, be careful not to hit
Run this line, log into Twitter, and get the authentication PIN. If you get an error message from Twitter saying the URL is expired, the probable cause is that you hit
It is important to name the result auth.vector as shown above, as the functions in the twinfoR package look for this global variable. If you give this result a different name, you must manually supply it to the Twitter API methods. Optionally, save this vector in order to skip the authentication process in the future.
Now we query the Twitter Search API for the search queries in the query_text table. We will not include sentiment analysis. For examples on how to include sentiment analysis in Twitter collections, see the documentation for insert_statuses, user_timeline_recursive,update_user_timelines, and update_search, as well as the US Politics vignette.
Because of the Twitter API rate limits, this could take a few minutes.
To wrap up part I, we can view a summary of what is in our Twitter database.
summarize_database(con)
#> No query user table.
#> Search queries: 4
#> Search categories:
#> location
#> since_id
#> Users: 11520
#> Statuses: 22012
#> Unique user mentions: 5684
#> Unique hashtags: 16128
#> Unique URLs: 7370
#> Total Images: 6430
#> Unique Images: 5511
#> Total relationships: 0
#> Database file size: 89MBFinally, to conclude this part of the vignette, we close the data connection.