update_pages: Update multiple Facebook pages

Description Usage Arguments Value Examples

View source: R/update_facebook_pages.R

Description

This function updates multiple Facebook pages with Rfacebook's getPage. makes use of the update_page function in this package. For each page in the provided character vector pages it looks for a previously stored data.frame (stored in the datadir under the name provided in the named vector pages with the file extension .rds). If there is one, it tries to scrape newer (and older) posts than the ones already stored in the data.frame. Otherwise it creats a new data.frame.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
update_pages(
  pages = NULL,
  token = NULL,
  datadir = "./data",
  go_back = TRUE,
  n_posts = 100,
  feed = FALSE,
  reactions = FALSE,
  max_repeats = 100,
  debug = FALSE
)

Arguments

pages

A named character vector. Names are the data file names, characters are the page names that will be updated (see example).

token

Either a temporary access token created at https://developers.facebook.com/tools/explorer or the OAuth token created with fbOAuth.

datadir

A directory containing the stored data sets (as "name.rds").

go_back

Go back in time, not only update newer posts, but also get older ones. Default is TRUE.

n_posts

The number of posts to scrape from each page, defaults to 100.

feed

If TRUE, the function will also return posts from each page that were made by others (not only the admin of the page).

reactions

If TRUE, will add variables to the data frame with the total count of reactions: love, haha, wow, sad, angry.

max_repeats

The number of repeated calls to scrape data backwards. If go_back is TRUE, there will be repeated calls to go back in time (each call gets the number of posts in n_posts). The backward scraping will stop after max_repeats is reached. Defaults to 100.

debug

If TRUE, more information will be printed.

Value

TRUE for all pages the update went through.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
## Not run: 
# You have to authenticate with Facebook's API first. For more in this visit
# Rfacebooks documentation.
fb_oauth <- Rfacebook::fbOAuth(app_id="123456789",
                               app_secret="1A2B3C4D",
                               extended_permissions = TRUE)

# A character vector is created
my_pages <- c(cnn = "cnn",
              bbc = "bbcnews")
# The two pages CNN and BBC news are updated and the results are stored in
# the user's home directory in the folder "temp". They are named cnn.rds and
# bbc.rds. If they do not already exist, both data sets are created.
update_pages(pages = my_pages, token = fb_outh, datadir = "~/temp")

## End(Not run)

jogrue/RfacebookHelperFunctions documentation built on May 7, 2020, 2:03 p.m.