-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes #137 (new getMembers function)
- Loading branch information
1 parent
0af6656
commit 0271880
Showing
5 changed files
with
86 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ Description: Provides an interface to the Facebook API. | |
Version: 0.6.17 | ||
Date: 2017-07-11 | ||
Author: Pablo Barbera <[email protected]>, Michael Piccirilli | ||
<[email protected]>, Andrew Geisler, Wouter van Atteveldt | ||
<[email protected]>, Andrew Geisler, Wouter van Atteveldt, Yan Turgeon | ||
Maintainer: Pablo Barbera <[email protected]> | ||
URL: https://github.com/pablobarbera/Rfacebook | ||
BugReports: https://github.com/pablobarbera/Rfacebook/issues | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#' @rdname getMembers | ||
#' @export | ||
#' @title | ||
#' Retrieve members from a public group | ||
#' | ||
#' @description | ||
#' \code{getMembers} retrieves members from a public group, up to 5000 members. | ||
#' | ||
#' @param page A group ID | ||
#' | ||
#' @author | ||
#' Yan Turgeon | ||
#' @seealso \code{\link{getPage}}, \code{\link{getPost}}, \code{\link{getCommentReplies}} | ||
|
||
#' @param token Either a temporary access token created at | ||
#' \url{https://developers.facebook.com/tools/explorer} or the OAuth token | ||
#' created with \code{fbOAuth}. | ||
#' | ||
#' @examples \dontrun{ | ||
#' ## 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) | ||
#'} | ||
|
||
getMembers <- function(group_id, token, n=5000, api=NULL){ | ||
url <- paste0('https://graph.facebook.com/', group_id, | ||
'/members?fields=id,name,first_name,last_name,administrator&limit=', n) | ||
|
||
# making query | ||
content <- callAPI(url=url, token=token) | ||
|
||
#if no data, return error message | ||
if (length(content$data)==0){ | ||
message("No groups with this name were found.") | ||
return(data.frame()) | ||
} | ||
|
||
# if data, return a data frame | ||
df <- data.frame( | ||
name = unlist(lapply(content$data, '[[', 'name')), | ||
id = unlist(lapply(content$data, '[[', 'id')), | ||
administrator = unlist(lapply(content$data, '[[', 'administrator')), | ||
stringsAsFactors=F) | ||
|
||
return(df) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.