Learn R Programming

SocialMediaLab (version 0.20.0)

CollectDataFacebook: Collect data from Facebook pages for generating different types of networks

Description

This function collects data from Facebook pages (i.e. post data and comments/likes data within posts), and structures the data into a data frame of class dataSource.facebook, ready for creating networks for further analysis.

Usage

CollectDataFacebook(pageName, rangeFrom, rangeTo, verbose, n, writeToFile,
  dynamic, credential = NULL)

Arguments

pageName
character string, specifying the name of the Facebook page. For example, if page is: https://www.facebook.com/StarWars, then pageName="StarWars".
rangeFrom
character string, specifying a 'start date' for data collection, in the format YYYY-MM-DD. For example, to collect data starting from July 4th 2015, rangeFrom would be "2015-07-04". Default value is current system date minus one week (i.e. th
rangeTo
character string, specifying an 'end date' for data collection, in the format YYYY-MM-DD. For example, to collect data until December 25th 2015, rangeFrom would be "2015-12-25". Default value is the current system date.
verbose
logical. If TRUE then this function will output runtime information to the console as it computes. Useful diagnostic tool for long computations. Default is FALSE.
n
numeric, maximum number of comments and likes to return (see getPost in Rfacebook package). Default value is 1000.
writeToFile
logical. If TRUE then the data is saved to file in current working directory (CSV format), with filename denoting rangeFrom, rangeTo, and pageName.
dynamic
logical. If TRUE then temporal data will be collected, which can be used to create dynamic networks (using function CreateDynamicNetwork). Note: Facebook API does not currently provide timestamp data for 'likes' on posts. Therefo
credential
Optional, a credential object created by Authenticate.

Value

  • A data frame object of class dataSource.facebook that can be used with CreateBimodalNetwork.

Details

CollectDataFacebook collects public 'post' data from a given Facebook page, including comments and 'likes' from within each post.

The function then finds and maps the relationships between users and posts, and structures these relationships into a format suitable for creating bimodal networks using CreateBimodalNetwork.

A date range must be specified for collecting post data using rangeFrom and rangeTo (i.e. data will be collected from posts posted within the date range). If no date range is supplied, then the default is the current system date minus one week (i.e. 7 days leading up to current system date).

See Also

AuthenticateWithFacebookAPI must be run first or no data will be collected, collectTemporalDataFacebook is used to collect temporal data suitable for dynamic networks (i.e. Facebook network that changes as a function of time).

Examples

Run this code
## Use your own values for myAppID and myAppSecret
  myAppID <- "123456789098765"
  myAppSecret <- "abc123abc123abc123abc123abc123ab"

  # Authenticate with the Facebook API using `AuthenticateWithFacebookAPI`
  fb_oauth <- AuthenticateWithFacebookAPI(appID=myAppID, appSecret=myAppSecret,
    extended_permissions=FALSE, useCachedToken=TRUE)

  # Run the `CollectDataFacebook` function and store the results in variable `myFacebookData`
  myFacebookData <- CollectDataFacebook(pageName="StarWars", rangeFrom="2015-05-01",
  rangeTo="2015-06-03",writeToFile=FALSE,verbose=TRUE)

  # Create a 'bimodal' network using \code{CreateBimodalNetwork}
  g_bimodal_facebook <- CreateBimodalNetwork(myFacebookData)

  # View descriptive information about the bimodal network
  g_bimodal_facebook

Run the code above in your browser using DataLab