This package provides methods for collecting and analyzing data from the Twitter REST APIs.
The goal of this package is to make it very easy to send user authenticated queries to the Twitter REST APIs, and collect, store, and analyze the response data.
Install from the compiled .zip file provided, as shown below from the R Console. After installing, check out the documentation.
> install.packages("twinfoR.zip",repos=NULL,type="binary")}
> ?twinfoR::twinfoR
If you do not have a copy of this package and would like one, send a request to cemarks at alum.mit.edu.
The authorize_app and authorize_IT provide methods to obtain access tokens needed for most API methods. These methods require the user to log on to Twitter and authorize a Twitter Application on the user’s account. You must have a Twitter account to authenticate.
Without a Twitter account, this package will be of very limited use. When calling either of the authentication functions, use care not to hit
All methods in this package that send requests to the Twitter REST APIs, with the single exception of twitter_request, look for user authentication credentials in a variable named auth.vector if credentials are not supplied to the function.
The workhorse function for this package is twitter_request. It can be used to send a user authenticated request to any of the REST API endpoints. See twitter_request documentation for details. All functions in this package that send requests to the Twitter REST APIs call this function.
This package offers several functions that access common Twitter REST API endpoints and return the response. These functions are:
search_tweets (see Twitter Search API)user_timeline (see User Timeline API)user_lookup (see User Lookup API)user_show (see Show User API)status_lookup (see Status Lookup API)status_show (see Show Status API)user_search (see User Search API)followers_ids (see Followers IDs API)friends_ids (see Friends IDs API)followers_list (see Followers List API)friends_list (see Friends List API)Often it is useful to call the methods listed in the preceding section recursively, in order to continue to collect relevant data from the Twitter REST APIs. Twitter imposes rate limits on all of these API end points. The following functions recursively query the end points, but include a delay for each query in order to build a large data set without exceeding the rate limits. The recursive nature of these functions varies. Some functions are designed to iterate through more inputs than a single query can handle, e.g., status_lookup_recursive; others page through more results than can be returned by a single query, e.g., search_tweets_recursive. The recursive API request functions are
search_tweets_recursiveuser_timeline_recursiveuser_lookup_recursivestatus_lookup_recursiveuser_search_recursivefollowers_list_recursivefriends_list_recursivefollowers_ids_recursivefriends_ids_recursiveThese recursive functions can return the results to the user, or, if a twitter_database connection is supplied, they will insert the results directly into the database. This specific database structure is provided in the next section.
This package offers a useful SQLite data structure that can be initialized or re-established useing the twitter_database function.
Understanding this data structure and familiarity with SQLite syntax will enable a user to carry out a wide array of analyses that are tailored for specific scenarios using this package. Of particular note, the query_users and query_text tables enable a user to specify and categorize query criteria that can be executed and analyzed over a time horizon. The following functions act on a twitter_database connection, and interact with the query_text and query_users tables, enabling a wide range of collection and analysis capabilities.
update_usersupdate_user_timelinesupdate_searchget_all_friendsget_all_followerssummarize_databaseAdditionally, the following functions enable direct updates to a twitter_database, and are called by some of the functions listed above.
upload_query_usersupload_query_textinsert_usersinsert_statusesinsert_followersinsert_friendsWhile many analyses are situation dependent, this package provides several useful, basic analysis and plotting functions that have applicability in many use cases. These functions include the following:
open_user (open a user profile in a browser)status_media (general function to manage images attached to Tweets)top_hashtagstop_usermentionstop_urlstop_mediatop_tweetersmost_likedmost_retweetedmost_popular_RT_in_samplemost_reachThe following functions produce plots of different aspects of the Twitter data.
wordcloud_plotsentiment_plotstimeplotThe vignettes for this package demonstrate many of features described above. They are:
twitter_database functionality.twitter_database functionality.