Learn R Programming

facebook.S4 (version 1.1.0)

FacebookPostsCollection: Build a collection of Facebook posts

Description

Connect to Facebook Graph API, get information from a list of public Facebook posts and build a FacebookPostsCollection-class instance.

Usage

FacebookPostsCollection(id, token = NULL, parameters = list(),
  fields = c("id", "from.fields(id,name)", "message", "created_time", "type",
  "link", "name"), feed = TRUE, n = getOption("facebook.maxitems"),
  metadata = FALSE, .progress = create_progress_bar())

Arguments

id

A character vector or a comma-delimited string of IDs or an existing Facebook Collection of any of the supported types (see below).

token

Either a temporary access token created at https://developers.facebook.com/tools/explorer or the OAuth token created with fbOAuth. If token NULL and id is a collection, use the token of the source collection. Otherwise, no query is performed to the Facebook Graph API and an empty collection is returned.

parameters

A list of parameters to be added to the Facebook Graph API query. For more information on the accepted parameters, see: https://developers.facebook.com/docs/graph-api/using-graph-api.

fields

A character vector with the fields to get for each id. If no value for a given field is found, it will be set to NULL.

feed

If id is a collection and feed is set to TRUE, the collection will also include posts written by others (not only by the owner of the collection items themselves). If id is not a collection or it is a FacebookGroupsCollection-class, the parameter is ignored.

n

If id is an iterable collection, then n is the maximum number of posts to be pulled for each element of the source collection in id. It can be set to Inf to pull out any available public post and assumes the default value from the value of facebook.maxitems global option if missing. If id is not a collection or cannot be iterated, the parameter is ignored.

metadata

If set to TRUE, the metadata for each ID is pulled with the data and the type slot is fed accordingly. Please note that setting this to TRUE could considerably slow down the execution time, as more queries are needed.

.progress

progress_bar object as defined in the plyr package. By default the none progress bar is used, which prints nothing to the console. See create_progress_bar for details.

Value

A collection of posts in a FacebookPostsCollection-class object.

Nesting fields

Due to the network-graph nature of Facebook data model, you can specify fields details for each field nesting .fields() clauses.

For example, if you need only id and source for the cover field, this is valid among others: cover.fields(id,source).

Following the same philosophy, if you need only id and name for the from node you can use from.fields(id,name).

Valid sources

Instead of a character vector, one of these collections can also be passed as parameter in id:

  • FacebookPostsCollection-class will build a collection with the shared posts from the posts of the source collection. It assumes the authors of the shared posts have granted the user_posts permission to the current application.

  • FacebookVideosCollection-class will build a collection with the shared posts from the videos of the source collection. It assumes the authors of the shared posts have granted the user_posts permission to the current application.

  • FacebookPagesCollection-class will build a collection with the posts written on the pages in the source collection.

  • FacebookUsersCollection-class will build a collection with the posts written on the walls of the users in the source collection. Users must have granted the user_posts permission to the current application to be able to perform this action.

  • FacebookGroupsCollection-class will build a collection with the posts written on the walls of the groups in the source collection. Users must have granted the user_managed_groups permission to the current application to be able to perform this action.

Details

FacebookPostsCollection is the constructor for the FacebookPostsCollection-class. It returns data about posts but doesn't return lists of comments or likes, although it does return an approximate total count for both (depending on privacy settings of the users).

See Also

FacebookPagesCollection, FacebookCommentsCollection, fbOAuth

Other Facebook Collection Constructors: FacebookAlbumsCollection, FacebookCommentsCollection, FacebookConversationsCollection, FacebookEventsCollection, FacebookGroupsCollection, FacebookLikesCollection, FacebookMessagesCollection, FacebookPagesCollection, FacebookPhotosCollection, FacebookReactionsCollection, FacebookUsersCollection, FacebookVideosCollection

Examples

Run this code
# NOT RUN {
## See examples for fbOAuth to know how token was created.
 load("fb_oauth")
 
## Getting information about two example Facebook Pages
 fb.pages <- FacebookPagesCollection(id = c("9thcirclegames",
                                           "NathanNeverSergioBonelliEditore"), 
                                     token = fb_oauth)
 
## Pull the latest 10 posts from each page
 fb.posts <- FacebookPostscollection(id = fb.pages, token = fb_oauth, n = 10)
 
## Pull all the available posts from each page
 fb.posts.inf <- FacebookPostscollection(id = fb.pages, token = fb_oauth, n = Inf)
 
## Convert the collection to a data frame
fb.posts.df <- as.data.frame(fb.posts)

# The same as before in a more compact fashion using the pipe operator
# chaining from a Pages Collection
 fb.posts.pipe <- FacebookPagesCollection(id = c("9thcirclegames", 
                                                "NathanNeverSergioBonelliEditore"),
                                          token = fb_oauth) %>% FacebookPostsCollection(n = 10)
   
## Build a collection of sharedposts from a posts collection
 fb.sharedposts <- FacebookPostsCollection(id = fb.posts, token = fb_oauth, n = Inf)
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab