update_page: Update or get posts from a Facebook page

Description Usage Arguments Value Examples

View source: R/update_facebook_pages.R

Description

This function updates one Facebook page with Rfacebook's getPage. It looks for a previously stored data.frame (readable by readRDS, e.g., bbcnews.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_page(
  page,
  token,
  datafile,
  go_back = TRUE,
  n_posts = 100,
  feed = FALSE,
  reactions = FALSE,
  max_repeats = 100,
  debug = FALSE
)

Arguments

page

A page name or ID.

token

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

datafile

The full path to a RDS data file.

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 the page, defaults to 100.

feed

If TRUE, the function will also return posts on the 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 if it ran 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)

# The BBC news page's posts are updated and stored in the user's home
# folder in the directory "temp" as "bbc.rds". If the file does not already
# exist a new file is created
update_page("bbcnews", fb_oauth, "~/temp/bbc.rds")

# The data set can be loaded with readRDS
readRDS("~/temp/bbc.rds")

## End(Not run)

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