Title: | Access to Facebook API via R |
---|---|
Description: | Provides an interface to the Facebook API. |
Authors: | Pablo Barbera <[email protected]>, Michael Piccirilli <[email protected]>, Andrew Geisler, Wouter van Atteveldt, Yan Turgeon |
Maintainer: | Pablo Barbera <[email protected]> |
License: | GPL-2 |
Version: | 0.6.18 |
Built: | 2025-02-22 05:40:27 UTC |
Source: | https://github.com/pablobarbera/rfacebook |
This package provides a series of functions that allow R users to access Facebook's API to get information about users and posts, and collect public status updates that mention specific keywords.
Pablo Barbera [email protected]
fbOAuth
, getUsers
,
getPost
, searchFacebook
,
updateStatus
, getFriends
,
getNetwork
, getPage
callAPI
is an internal function to run an API request.
callAPI(url, token, api = NULL)
callAPI(url, token, api = NULL)
url |
URL of API request |
token |
Either a temporary access token created at
https://developers.facebook.com/tools/explorer or the OAuth token
created with |
api |
API version. e.g. "v2.8". |
fbOAuth
creates a long-lived OAuth access token that enables R to make
authenticated calls to the Facebook API. The token can be saved as a
file in disk to be re-used in future sessions. This function relies on the
httr
package to create the OAuth token, and is a simplified version
of one of its examples.
This function will automatically detect the API version for the token you create.
fbOAuth(app_id, app_secret, extended_permissions = FALSE, legacy_permissions = FALSE, scope = NULL)
fbOAuth(app_id, app_secret, extended_permissions = FALSE, legacy_permissions = FALSE, scope = NULL)
app_id |
numeric, App ID of application to be used to create OAUth token. Available at https://developers.facebook.com/apps |
app_secret |
string, App Secret of application to be used to create OAUth token. Available at https://developers.facebook.com/apps, in Basic Settings panel. |
extended_permissions |
If |
legacy_permissions |
For tokens created with old versions of the API, this option adds the "read_stream" permission |
scope |
Specify an explicit lists of permissions to ask (overrides extended_permissions) |
There are two different ways of making authenticated requests. One is to obtain a temporary access token from https://developers.facebook.com/tools/explorer/, which can be used as argument in any of the functions in Rfacebook. An example is shown below.
However, this token has a 2-hour lifetime by default and after it expires, it needs to be renewed. The second alternative is to create an OAuth token. The process to create it is a bit more tedious. It is divided in three steps.
First, go to https://developers.facebook.com/apps, register as a developer and create a new app. You will also need a verified Facebook account. After that, click in "Show" under "App Secret" to find your 'App ID' and 'App Secret'.
Second, run the fbOAuth
function with your "App ID" and "App Secret" as
arguments. It will return a URL, which you will need to paste into the "Website with
Facebook login" field in your App Settings on Facebook. Once you've done so, press Enter.
Third, after pressing Enter, R will try to open a browser window to sign the token. If everything works well, you will get a message that says you can return to R. If not, try again in a few minutes to make sure your app had its settings updated properly.
To ensure proper functioning of the "getInsights" function-family you will need to specify the exact permissions granted to your app. As this is (to our knowledge) currently not possible through the R based authentication process, please follow these steps:
-> Create App as mentioned above. 1. Open the "Graph API Explorer": https://developers.facebook.com/tools/explorer/ 2. Select your app in the upper right corner 3. Click "Get Token" -> "Get Access Token" 4. In the popup navigate to "Extended Permissions" and select "Insights" 5. Confirm 6. Ignore the following warning message ("Submit for Login Review...") and confirm again. 6. Go back to R and run fbOAuth with extended_permissions (still) set to FALSE. -> See third step for possible messages concerning token creation.
Pablo Barbera [email protected]
getUsers
, getPost
, searchFacebook
## Not run: ## an example of an authenticated request after creating the OAuth token ## where app_id and app_secret are fictitious, and token is saved for ## future sessions fb_oauth <- fbOAuth(app_id="123456789", app_secret="1A2B3C4D") save(fb_oauth, file="fb_oauth") load("fb_oauth") me <- getUsers("me", token=fb_oauth) me$username ## an example of a request using a temporary access token token <- "XXXXXXAAAAAAA1111" me <- getUsers("me", token=token) ## End(Not run)
## Not run: ## an example of an authenticated request after creating the OAuth token ## where app_id and app_secret are fictitious, and token is saved for ## future sessions fb_oauth <- fbOAuth(app_id="123456789", app_secret="1A2B3C4D") save(fb_oauth, file="fb_oauth") load("fb_oauth") me <- getUsers("me", token=fb_oauth) me$username ## an example of a request using a temporary access token token <- "XXXXXXAAAAAAA1111" me <- getUsers("me", token=token) ## End(Not run)
getCheckins
retrieves information about a friend's checkins
getCheckins(user, n = 10, token, tags = FALSE, api = NULL)
getCheckins(user, n = 10, token, tags = FALSE, api = NULL)
user |
A user ID or screen name. |
n |
Maximum number of checkins to return for each user. |
token |
Either a temporary access token created at
https://developers.facebook.com/tools/explorer or the OAuth token
created with |
tags |
If |
api |
API version. e.g. "v2.8". |
This function requires the use of an OAuth token with the following permissions: user_status, user_checkins, friends_status, friends_checkins
Check-in search was deprecated with version 2.0 of the Facebook Graph API.
Pablo Barbera [email protected]
## Not run: token <- 'XXXXX' my_checkins <- getCheckins(user="me", token=token) ## End(Not run)
## Not run: token <- 'XXXXX' my_checkins <- getCheckins(user="me", token=token) ## End(Not run)
getCommentReplies
retrieves the list of comments replying to
an individual comment on a post by a public Facebook page.
getCommentReplies(comment_id, token, n = 500, replies = TRUE, likes = FALSE, n.likes = n, n.replies = n, api = NULL)
getCommentReplies(comment_id, token, n = 500, replies = TRUE, likes = FALSE, n.likes = n, n.replies = n, api = NULL)
comment_id |
A comment ID |
token |
Either a temporary access token created at
https://developers.facebook.com/tools/explorer or the OAuth token
created with |
n |
numeric, maximum number of replies and likes to return. |
replies |
logical, default is |
likes |
logical, default is |
n.likes |
numeric, maximum number of likes to return. Default is |
n.replies |
numeric, maximum number of replies to return. Default is
|
api |
API version. e.g. "v2.8". |
getCommentReplies
returns a list with three components: comment
,
replies
, and likes
. First, comment
contains information
about the original comment: author, creation date, id, counts of likes and comments,
etc. Second, replies
is a data frame with information about the replies
to the comment (author, message, creation time, id). Finally, likes
is
data frame that contains names and Facebook IDs of all the users that liked the comment.
Note that user information (from_id and from_name) are only returned if the token used to authenticate is a Page access token. For more information, see: https://developers.facebook.com/docs/graph-api/reference/v2.10/comment
Yan Turgeon
## Not run: ## See examples for fbOAuth to know how token was created. ## Getting information about Facebook's Facebook Page load("fb_oauth") fb_page <- getPage(page="facebook", token=fb_oauth) ## Getting information and likes/comments about most recent post post <- getPost(post=fb_page$id[1], n=2000, token=fb_oauth) ## Downloading list of replies to first comment replies <- getCommentReplies(comment_id=post$comments$id[1], token=fb_oauth) ## End(Not run)
## Not run: ## See examples for fbOAuth to know how token was created. ## Getting information about Facebook's Facebook Page load("fb_oauth") fb_page <- getPage(page="facebook", token=fb_oauth) ## Getting information and likes/comments about most recent post post <- getPost(post=fb_page$id[1], n=2000, token=fb_oauth) ## Downloading list of replies to first comment replies <- getCommentReplies(comment_id=post$comments$id[1], token=fb_oauth) ## End(Not run)
getEvents
retrieves event information from a public Facebook group or page.
getEvents(page, token, api = "v2.9")
getEvents(page, token, api = "v2.9")
page |
Facebook ID for the group or page. |
token |
Either a temporary access token created at
https://developers.facebook.com/tools/explorer or the OAuth token
created with |
api |
API version. e.g. "v2.8". |
Pablo Barbera [email protected]
## Not run: load("fb_oauth") ## Downloading events from Playa Vista Farmers' Market events <- getEvents(page="playavistaFM", token=fb_oauth) ## End(Not run)
## Not run: load("fb_oauth") ## Downloading events from Playa Vista Farmers' Market events <- getEvents(page="playavistaFM", token=fb_oauth) ## End(Not run)
getFQL
connects to Facebook's Graph API and executes a FQL query.
See https://developers.facebook.com/docs/technical-guides/fql/ for
an overview of the Facebook Query Language.
getFQL(query, token)
getFQL(query, token)
query |
Text of query |
token |
Either a temporary access token created at
https://developers.facebook.com/tools/explorer or the OAuth token
created with |
Pablo Barbera [email protected]
## Not run: ## See examples for fbOAuth to know how token was created. ## Getting list of friends of authenticated user load("fb_oauth") d <- getFQL("SELECT uid2 FROM friend WHERE uid1=me()", token=fb_oauth) ## End(Not run)
## Not run: ## See examples for fbOAuth to know how token was created. ## Getting list of friends of authenticated user load("fb_oauth") d <- getFQL("SELECT uid2 FROM friend WHERE uid1=me()", token=fb_oauth) ## End(Not run)
getFriends
retrieves information about the user's friends.
getFriends(token, simplify = FALSE)
getFriends(token, simplify = FALSE)
token |
Either a temporary access token created at
https://developers.facebook.com/tools/explorer or the OAuth token
created with |
simplify |
If |
This function requires the use of a OAuth token with extended permissions. After the introduction of version 2.0 of the Graph API, only friends who are using the application that you used to generate the token to query the API will be returned.
Pablo Barbera [email protected]
## Not run: ## Copy and paste token created at FB Graph API Explorer token <- "XXXXXX" my_friends <- getFriends(token=token, simplify=TRUE) ## Since users are ordered by ID, this will return 10 oldest user accounts head(my_friends, n=10) ## End(Not run)
## Not run: ## Copy and paste token created at FB Graph API Explorer token <- "XXXXXX" my_friends <- getFriends(token=token, simplify=TRUE) ## Since users are ordered by ID, this will return 10 oldest user accounts head(my_friends, n=10) ## End(Not run)
getGroup
retrieves information from a public Facebook group.
getGroup(group_id, token, n = 25, since = NULL, until = NULL, feed = TRUE, api = NULL)
getGroup(group_id, token, n = 25, since = NULL, until = NULL, feed = TRUE, api = NULL)
group_id |
Facebook ID for the group. Note that this is different from
the name on the URL. You can use |
token |
Either a temporary access token created at
https://developers.facebook.com/tools/explorer or the OAuth token
created with |
n |
Number of posts of page to return. Note that number can be sometimes higher or lower, depending on status of API. |
since |
A UNIX timestamp or strtotime data value that points to the start of the time range to be searched. For more information on the accepted values, see: http://php.net/manual/en/function.strtotime.php |
until |
A UNIX timestamp or strtotime data value that points to the end of the time range to be searched. For more information on the accepted values, see: http://php.net/manual/en/function.strtotime.php |
feed |
If |
api |
API version. e.g. "v2.8". |
Pablo Barbera [email protected]
## Not run: ## Find Facebook ID for R-Users Facebook group load("fb_oauth") ids <- searchGroup(name="rusers", token=fb_oauth) ids[1,] # id = 18533493739 ## Downloading posts from R-Users Facebook group group <- getGroup(group_id=18533493739, token=fb_oauth) ## Downloading posts from R-Users Facebook group in January 2013 group <- getGroup(group_id=18533493739, token=fb_oauth, since='2013/01/01', until='2013/01/31') ## End(Not run)
## Not run: ## Find Facebook ID for R-Users Facebook group load("fb_oauth") ids <- searchGroup(name="rusers", token=fb_oauth) ids[1,] # id = 18533493739 ## Downloading posts from R-Users Facebook group group <- getGroup(group_id=18533493739, token=fb_oauth) ## Downloading posts from R-Users Facebook group in January 2013 group <- getGroup(group_id=18533493739, token=fb_oauth, since='2013/01/01', until='2013/01/31') ## End(Not run)
getInsights
retrieves information from an owned Facebook page. Note
that you must specify wich metric from insights you need and the period.
To request multiple metrics at one time, pass a vector of metric names with a vector
of periods of the same length. If only one period is supplied, it will apply to each metric.
Please refer to Facebook's documentation for valid combinations of objects, metrics and periods.
Note that some insights require a page access token, see getPageToken
getInsights(object_id, token, metric, period = "day", parms = NA, version = 2.3, n = 5)
getInsights(object_id, token, metric, period = "day", parms = NA, version = 2.3, n = 5)
object_id |
An object (page, post, domain) ID. |
token |
Either a temporary access token created at
https://developers.facebook.com/tools/explorer or the OAuth token
created with |
metric |
The metric(s) which you want to get values for. |
period |
Time intervals to return |
parms |
Optional argument that can be used to append additional
parameters. For example, |
version |
specifies what API version to use in the request. Version 2.5 is default. |
n |
Number of time intervals of metric values to return. Note that all metrics returned will be multiple of 3, except for lifetime period. Default n is 5 |
The current list of supported metrics and periods is: page_fan_adds, page_fan_removes, page_views_login, page_views_login, page_views_logout, page_views, page_story_adds, page_impressions, page_posts_impressions, page_consumptions, post_consumptions_by_type, page_consumptions, and page_fans_country.
For more information, see: https://developers.facebook.com/docs/graph-api/reference/v2.5/insights
Danilo Silva [email protected] Eduardo Carvalho [email protected] Andrew Geisler https://github.com/andrewgeisler
## Not run: ## See examples for fbOAuth to know how token was created. ## Getting page impressions for Facebook's Facebook Page ## (only owner or admin of page) load("fb_oauth") insights <- getInsights(object_id="20531316728", token=fb_oauth, metric='page_impressions') ## Getting post impressions for a random Facebook's page post ## (only owner or admin of page) insights <- getInsights(object_id='221568044327801_754789777921289', token=fb_oauth, metric='post_impressions', period='days_28') ## Getting page fans for date range ## (only owner or admin of page) insights <- getInsights(object_id='221568044327801', token=fb_oauth, metric=c'page_fans', period='lifetime', parms='&since=2015-01-01&until=2015-01-31', version=2.5) #' ## Getting page fans AND page impressions for date range ## (only owner or admin of page) insights <- getInsights(object_id='221568044327801', token=fb_oauth, metric=c('page_fans','page_impressions'), period=c('lifetime','day'), parms='&since=2015-01-01&until=2015-01-31') ## Count of fans by country insights <- getInsights(object_id='221568044327801_754789777921289', token=fb_oauth, metric='page_fans_country', period='lifetime') ## End(Not run)
## Not run: ## See examples for fbOAuth to know how token was created. ## Getting page impressions for Facebook's Facebook Page ## (only owner or admin of page) load("fb_oauth") insights <- getInsights(object_id="20531316728", token=fb_oauth, metric='page_impressions') ## Getting post impressions for a random Facebook's page post ## (only owner or admin of page) insights <- getInsights(object_id='221568044327801_754789777921289', token=fb_oauth, metric='post_impressions', period='days_28') ## Getting page fans for date range ## (only owner or admin of page) insights <- getInsights(object_id='221568044327801', token=fb_oauth, metric=c'page_fans', period='lifetime', parms='&since=2015-01-01&until=2015-01-31', version=2.5) #' ## Getting page fans AND page impressions for date range ## (only owner or admin of page) insights <- getInsights(object_id='221568044327801', token=fb_oauth, metric=c('page_fans','page_impressions'), period=c('lifetime','day'), parms='&since=2015-01-01&until=2015-01-31') ## Count of fans by country insights <- getInsights(object_id='221568044327801_754789777921289', token=fb_oauth, metric='page_fans_country', period='lifetime') ## End(Not run)
getLikes
retrieves information about the authenticated use
only (not any friend). To retrieve the number of likes for a page,
use getUsers
with the page IDs.
getLikes(user = "me", n = 500, token)
getLikes(user = "me", n = 500, token)
user |
The name of the user. By default, "me". |
n |
Maximum number of likes to return for each user. |
token |
Either a temporary access token created at
https://developers.facebook.com/tools/explorer or the OAuth token
created with |
This function requires the use of an OAuth token with the following permission: user_likes
Pablo Barbera [email protected]
## Not run: token <- 'XXXXX' my_likes <- getLikes(user="me", token=token) ## End(Not run)
## Not run: token <- 'XXXXX' my_likes <- getLikes(user="me", token=token) ## End(Not run)
getMembers
retrieves members from a public group, up to 5000 members.
getMembers(group_id, token, n = 5000, api = NULL)
getMembers(group_id, token, n = 5000, api = NULL)
token |
Either a temporary access token created at
https://developers.facebook.com/tools/explorer or the OAuth token
created with |
page |
A group ID |
Yan Turgeon
getPage
, getPost
, getCommentReplies
## Not run: ## Find Facebook ID for R-Users Facebook group load("fb_oauth") ids <- searchGroup(name="rusers", token=fb_oauth) ids[1,] # id = 18533493739 ## Retrieves members ID for R-Users Facebook group members <- getMembers(group_id="18533493739", token=fb_oauth) ## End(Not run)
## Not run: ## Find Facebook ID for R-Users Facebook group load("fb_oauth") ids <- searchGroup(name="rusers", token=fb_oauth) ids[1,] # id = 18533493739 ## Retrieves members ID for R-Users Facebook group members <- getMembers(group_id="18533493739", token=fb_oauth) ## End(Not run)
getNetwork
retrieves the list of mutual friendships and returns the
adjacency matrix or edge list for the network representing the neighborhood
of the authenticated user.
getNetwork(token, format = "edgelist", verbose = TRUE)
getNetwork(token, format = "edgelist", verbose = TRUE)
token |
Either a temporary access token created at
https://developers.facebook.com/tools/explorer or the OAuth token
created with |
format |
Either "edgelist" for a list of edges in the network or "adj.matrix" for an adjacenty matrix of dimensions (n x n), with n being the number of friends, and 0 or 1 indicating whether friend i is also friends with friend j. |
verbose |
logical, default is |
This function requires the use of an OAuth token with extended permissions.
After the introduction of version 2.0 of the Graph API, only friends who are using the application will be returned.
Pablo Barbera [email protected]
## Not run: ## See examples for fbOAuth to know how token was created. ## Copy and paste token created at FB Graph API Explorer token <- "XXXXXX" mat <- getNetwork(token=token, format="adj.matrix") library(igraph) network <- graph.adjacency(mat, mode="undirected") pdf("network_plot.pdf") plot(network) dev.off() ## End(Not run)
## Not run: ## See examples for fbOAuth to know how token was created. ## Copy and paste token created at FB Graph API Explorer token <- "XXXXXX" mat <- getNetwork(token=token, format="adj.matrix") library(igraph) network <- graph.adjacency(mat, mode="undirected") pdf("network_plot.pdf") plot(network) dev.off() ## End(Not run)
getNewsfeed
retrieves status updates from the authenticated user's
News Feed
getNewsfeed(token, n = 200)
getNewsfeed(token, n = 200)
token |
Either a temporary access token created at
https://developers.facebook.com/tools/explorer or the OAuth token
created with |
n |
Maximum number of posts to return. |
Pablo Barbera [email protected]
## Not run: ## See examples for fbOAuth to know how token was created. ## Capture 100 most recent posts on my newsfeed load("fb_oauth") my_newsfeed <- getNewsfeed(token=fb_oauth, n=100) ## End(Not run)
## Not run: ## See examples for fbOAuth to know how token was created. ## Capture 100 most recent posts on my newsfeed load("fb_oauth") my_newsfeed <- getNewsfeed(token=fb_oauth, n=100) ## End(Not run)
getPage
retrieves information from a public Facebook page. Note that
information about users that have turned on the "follow" option on their
profile can also be retrieved with this function.
getPage(page, token, n = 25, since = NULL, until = NULL, feed = FALSE, reactions = FALSE, verbose = TRUE, api = NULL)
getPage(page, token, n = 25, since = NULL, until = NULL, feed = FALSE, reactions = FALSE, verbose = TRUE, api = NULL)
page |
A page ID or page name. |
token |
Either a temporary access token created at
https://developers.facebook.com/tools/explorer or the OAuth token
created with |
n |
Number of posts of page to return. Note that number can be sometimes higher or lower, depending on status of API. |
since |
A UNIX timestamp or strtotime data value that points to the start of the time range to be searched. For more information on the accepted values, see: http://php.net/manual/en/function.strtotime.php |
until |
A UNIX timestamp or strtotime data value that points to the end of the time range to be searched. For more information on the accepted values, see: http://php.net/manual/en/function.strtotime.php |
feed |
If |
reactions |
If |
verbose |
If |
api |
API version. e.g. "v2.8". |
This function will only return information from public pages, not users with public profiles.
The since
and until
parameters are applied to the updated_time
field in the post objects, and not the created_time
. As a result, this function
might return old posts that have been updated recently.
comments_count
refers to the total of comments, including nested comments (replies).
It might be different from the total number of comments available through the API if
some comments have been deleted.
Pablo Barbera [email protected]
## Not run: ## See examples for fbOAuth to know how token was created. ## Getting information about Facebook's Facebook Page load("fb_oauth") fb_page <- getPage(page="facebook", token=fb_oauth) ## Getting posts on Humans of New York page, including posts by others users ## (not only owner of page) page <- getPage(page="humansofnewyork", token=fb_oauth, feed=TRUE) ## Getting posts on Humans of New York page in January 2013 page <- getPage(page="humansofnewyork", token=fb_oauth, n=1000, since='2013/01/01', until='2013/01/31') ## End(Not run)
## Not run: ## See examples for fbOAuth to know how token was created. ## Getting information about Facebook's Facebook Page load("fb_oauth") fb_page <- getPage(page="facebook", token=fb_oauth) ## Getting posts on Humans of New York page, including posts by others users ## (not only owner of page) page <- getPage(page="humansofnewyork", token=fb_oauth, feed=TRUE) ## Getting posts on Humans of New York page in January 2013 page <- getPage(page="humansofnewyork", token=fb_oauth, n=1000, since='2013/01/01', until='2013/01/31') ## End(Not run)
Gets a page access token that can be used to e.g. get insights for a page.
getPageToken(page, token)
getPageToken(page, token)
page |
A page ID or page name. |
token |
the token (with scope 'manage_pages') of a user that has admin access to the page |
the page access token string
## Not run: ## Get a normal access token with manage_pages scope token = fbOAuth(app_id, app_secret, scope="manage_pages") ## Get a page access token for a page page_token = getPageToken(page, token) ## Get page insights getInsights(page, token=page_token, metric = "page_impressions") ## End(Not run)
## Not run: ## Get a normal access token with manage_pages scope token = fbOAuth(app_id, app_secret, scope="manage_pages") ## Get a page access token for a page page_token = getPageToken(page, token) ## Get page insights getInsights(page, token=page_token, metric = "page_impressions") ## End(Not run)
getPost
retrieves information about a public Facebook post, including
list of comments and likes.
getPost(post, token, n = 500, comments = TRUE, likes = (!reactions), reactions = FALSE, n.likes = n, n.comments = n, n.reactions = n, api = NULL)
getPost(post, token, n = 500, comments = TRUE, likes = (!reactions), reactions = FALSE, n.likes = n, n.comments = n, n.reactions = n, api = NULL)
post |
A post ID |
token |
Either a temporary access token created at
https://developers.facebook.com/tools/explorer or the OAuth token
created with |
n |
numeric, maximum number of comments and likes to return. |
comments |
logical, default is |
likes |
logical, default is |
reactions |
logical, default is |
n.likes |
numeric, maximum number of likes to return. Default is |
n.comments |
numeric, maximum number of comments to return. Default is
|
n.reactions |
numeric, maximum number of reactions to return. Default is
|
api |
API version. e.g. "v2.8". |
getPost
returns a list with up to four components: post
,
likes
, comments
, and reactions
.
post
contains information about the post: author, creation date, id,
counts of likes, comments, and shares, etc.
likes
is a data frame that contains names and Facebook IDs of all
the users that liked the post.
comments
is a data frame with information about the comments to
the post (author, message, creation time, id). To download also the replies
to specific comments, see getCommentReplies
. Note that the total
number of comments may be different from the number report in comments_count
if some comments have been deleted.
Pablo Barbera [email protected]
## Not run: ## See examples for fbOAuth to know how token was created. ## Getting information about Facebook's Facebook Page load("fb_oauth") fb_page <- getPage(page="facebook", token=fb_oauth) ## Getting information and likes/comments about most recent post post <- getPost(post=fb_page$id[1], n=2000, token=fb_oauth) ## End(Not run)
## Not run: ## See examples for fbOAuth to know how token was created. ## Getting information about Facebook's Facebook Page load("fb_oauth") fb_page <- getPage(page="facebook", token=fb_oauth) ## Getting information and likes/comments about most recent post post <- getPost(post=fb_page$id[1], n=2000, token=fb_oauth) ## End(Not run)
getReactions
retrieves information from a single or multiple posts,
returning the total count of reactions of each type (like, love, haha,
wow, sad, angry).
getReactions(post, token, verbose = TRUE, api = NULL)
getReactions(post, token, verbose = TRUE, api = NULL)
post |
A post ID, or a vector of post IDs |
token |
Either a temporary access token created at
https://developers.facebook.com/tools/explorer or the OAuth token
created with |
verbose |
logical, default is |
api |
API version. e.g. "v2.8". |
The solution implemented here is based on this Stack Overflow response: http://stackoverflow.com/questions/36930414/how-can-i-get-facebook-graph-api-reaction-summary-count-separately
Pablo Barbera [email protected]
## Not run: ## See examples for fbOAuth to know how token was created. ## Getting information about Facebook's Facebook Page load("fb_oauth") fb_page <- getPage(page="facebook", token=fb_oauth) ## Getting reactions for most recent post post <- getReactions(post=fb_page$id[1], token=fb_oauth) ## End(Not run)
## Not run: ## See examples for fbOAuth to know how token was created. ## Getting information about Facebook's Facebook Page load("fb_oauth") fb_page <- getPage(page="facebook", token=fb_oauth) ## Getting reactions for most recent post post <- getReactions(post=fb_page$id[1], token=fb_oauth) ## End(Not run)
getUsers
retrieves public information about one or more Facebook users.
After version 2.0 of the Facebook API, only id, name, and picture are available through the API. All the remaining fields will be missing.
getUsers(users, token, private_info = FALSE, api = "v2.9")
getUsers(users, token, private_info = FALSE, api = "v2.9")
users |
A vector of user IDs. |
token |
Either a temporary access token created at
https://developers.facebook.com/tools/explorer or the OAuth token
created with |
private_info |
If |
Pablo Barbera [email protected]
getFriends
, getPost
, searchFacebook
## Not run: ## See examples for fbOAuth to know how token was created. ## Getting information about the authenticated user load("fb_oauth") fb <- getUsers("me", token=fb_oauth) fb$username ## End(Not run)
## Not run: ## See examples for fbOAuth to know how token was created. ## Getting information about the authenticated user load("fb_oauth") fb <- getUsers("me", token=fb_oauth) fb$username ## End(Not run)
searchFacebook
retrieves public status updates that mention a given keyword
searchFacebook(string, token, n = 200, since = NULL, until = NULL)
searchFacebook(string, token, n = 200, since = NULL, until = NULL)
string |
string or string vector containing keywords to search. Note that the returned results will contain any of the keywords. It is not possible to search for status updates that include all of the keywords. |
token |
An OAuth token created with |
n |
Maximum number of posts to return. |
since |
A UNIX timestamp or strtotime data value that points to the start of the time range to be searched. For more information on the accepted values, see: http://php.net/manual/en/function.strtotime.php |
until |
A UNIX timestamp or strtotime data value that points to the end of the time range to be searched. For more information on the accepted values, see: http://php.net/manual/en/function.strtotime.php |
Note: Public post search was deprecated with version 2.0 of the Facebook Graph API, and therefore this function will no longer work. For more information about these changes, go to: https://developers.facebook.com/docs/apps/changelog
The function will only work for OAuth tokens generated with version 1.0 of the API, which can no longer be created.
The search is performed also on the text of the comments too, which explains why some of the returned messages do not mention the string that is being searched.
Note that only messages up to around two weeks old or less can be returned.
Pablo Barbera [email protected]
## Not run: ## Searching 100 public posts that mention "facebook" posts <- searchFacebook( string="facebook", token=fb_oauth, n=100 ) ## Searching 100 public posts that mention "facebook" from yesterday posts <- searchFacebook( string="facebook", token=fb_oauth, n=100, since = "yesterday 00:00", until = "yesterday 23:59" ) ## End(Not run)
## Not run: ## Searching 100 public posts that mention "facebook" posts <- searchFacebook( string="facebook", token=fb_oauth, n=100 ) ## Searching 100 public posts that mention "facebook" from yesterday posts <- searchFacebook( string="facebook", token=fb_oauth, n=100, since = "yesterday 00:00", until = "yesterday 23:59" ) ## End(Not run)
Use searchGroup
in combination with getGroup
to scrape
public posts on Facebook groups.
searchGroup(name, token, n = 25, api = NULL)
searchGroup(name, token, n = 25, api = NULL)
name |
Name of Facebook group (in URL) |
token |
Either a temporary access token created at
https://developers.facebook.com/tools/explorer or the OAuth token
created with |
n |
Number of groups to return. Default is up to 25. |
api |
API version. e.g. "v2.8". |
## Not run: ## Find Facebook ID for R-Users Facebook group load("fb_oauth") ids <- searchGroup(name="rusers", token=fb_oauth) ids[1,] # id = 18533493739 ## Downloading posts from R-Users Facebook group group <- getGroup(group_id=18533493739, token=fb_oauth) ## Downloading posts from R-Users Facebook group in January 2013 group <- getGroup(group_id=18533493739, token=fb_oauth, since='2013/01/01', until='2013/01/31') ## End(Not run)
## Not run: ## Find Facebook ID for R-Users Facebook group load("fb_oauth") ids <- searchGroup(name="rusers", token=fb_oauth) ids[1,] # id = 18533493739 ## Downloading posts from R-Users Facebook group group <- getGroup(group_id=18533493739, token=fb_oauth) ## Downloading posts from R-Users Facebook group in January 2013 group <- getGroup(group_id=18533493739, token=fb_oauth, since='2013/01/01', until='2013/01/31') ## End(Not run)
searchPages
retrieves public pages that mention a given keyword
searchPages(string, token, n = 200)
searchPages(string, token, n = 200)
string |
string or string vector containing keywords to search. When searching using multiple keywords, the returned results will be pages whose name contains all the keywords. |
token |
Either a temporary access token created at
https://developers.facebook.com/tools/explorer or the OAuth token
created with |
n |
Maximum number of pages to return. |
Pablo Barbera [email protected], Joel Gombin [email protected]
## Not run: ## See examples for fbOAuth to know how token was created. ## Searching 100 public pages that mention "facebook" load("fb_oauth") pages <- searchPages( string="facebook", token=fb_oauth, n=100 ) ## End(Not run)
## Not run: ## See examples for fbOAuth to know how token was created. ## Searching 100 public pages that mention "facebook" load("fb_oauth") pages <- searchPages( string="facebook", token=fb_oauth, n=100 ) ## End(Not run)
updateStatus
sends a status update that will be displayed
on the Facebook profile of the authenticated user.
updateStatus(text, token, link = NULL)
updateStatus(text, token, link = NULL)
text |
string, text of the status update |
token |
Either a temporary access token created at
https://developers.facebook.com/tools/explorer or the OAuth token
created with |
link |
string, URL of link to be added to status update |
Pablo Barbera [email protected], Zakharov Kyrylo (https://github.com/Amice13)
## Not run: ## See examples for fbOAuth to know how token was created. load("fb_oauth") updateStatus("this is just a test", token=fb_oauth) ## End(Not run)
## Not run: ## See examples for fbOAuth to know how token was created. load("fb_oauth") updateStatus("this is just a test", token=fb_oauth) ## End(Not run)