├── .Rbuildignore ├── .gitignore ├── DESCRIPTION ├── LICENSE ├── NAMESPACE ├── R ├── fbSetAccount.R ├── fbSimLikes.R └── fbSimPosts.R ├── README.md ├── fbSim.Rproj └── man ├── fbSetAccount.Rd ├── fbSimLikes.Rd └── fbSimPosts.Rd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .Ruserdata 5 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: fbSim 2 | Title: Simulates a Facebook user's behavior 3 | Version: 0.1-1 4 | Authors@R: c( 5 | person("Moreno", "Mancosu", email = "moreno.mancosu@unito.it", 6 | role = c("aut","cre")), 7 | person("Federico", "Vegetti", email = "vegetti.fede@gmail.com", 8 | role = c("aut"))) 9 | Description: fbSim is a set of functions aiming at simulating registered users' behavior on Facebook. 10 | The functions employs automatic browsing features of Google Chrome and saves data "seen" by users in a data frame. 11 | Depends: R (>= 3.4.1), XML, devtools, getPass, digest, RSelenium, wdman, binman, anytime 12 | Imports: methods, stats 13 | SystemRequirements: 14 | License: GPL-3 15 | LazyData: true 16 | RoxygenNote: 6.1.1 17 | Encoding: UTF-8 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(fbSetAccount) 4 | export(fbSimLikes) 5 | export(fbSimPosts) 6 | -------------------------------------------------------------------------------- /R/fbSetAccount.R: -------------------------------------------------------------------------------- 1 | #' Set a (permanent) Fb account 2 | #' 3 | #' Produces a folder containing Chrome profile information and saved Fb password and email 4 | #' 5 | #' @param user Your Facebook e-mail (The Fb password is requested once the function is called). 6 | #' @param user_path The location of the folder (folder name included). 7 | #' @param chrome_ver The installed version of Google Chrome. To get the Chrome version go to chrome://version in Chrome's address bar and use the first two digits - e.g. if the version is 73.0.3683.86, just use 73). 8 | #' 9 | #' @return A folder in \code{"user_path"} containing a Chrome profile ready to access to Facebook. 10 | #' @author Moreno Mancosu \email{moreno.mancosu@@carloalberto.org}, Federico Vegetti \email{vegetti.fede@@gmail.com} 11 | #' 12 | #' @examples 13 | #' user <- "user@@domain.org" 14 | #' user_path <- "C:/Users/Username/Desktop/Chrome_profile" 15 | #' fbSetAccount(user, user_path) 16 | #' 17 | #' @export 18 | 19 | fbSetAccount <- function(user, user_path = "Chrome_profile",chrome_ver = 86) { 20 | 21 | #============================================================================================ 22 | #### Check whether arguments are ok 23 | #### Namely, whether they are not missing... 24 | if (methods::missingArg(user) | !exists("user", envir = parent.frame())) { 25 | stop("missing argument: user",call.=FALSE) 26 | } 27 | #### ... or non-character 28 | if (is.character(user)==FALSE | is.character(user_path)==FALSE) { 29 | stop("all arguments must be a character",call.=FALSE) 30 | } 31 | 32 | ##### 33 | 34 | ver <- "86.0.4240.22" 35 | if(chrome_ver==86) { 36 | ver <- "86.0.4240.22" 37 | } else if(chrome_ver==85) { 38 | ver <- "85.0.4183.87" 39 | } else if(chrome_ver==84) { 40 | ver <- "84.0.4147.30" 41 | } else if(chrome_ver==83) { 42 | ver <- "83.0.4103.39" 43 | } else if(chrome_ver==81) { 44 | ver <- "81.0.4044.138" 45 | } else if(chrome_ver==80) { 46 | ver <- "80.0.3987.106" 47 | } else if(chrome_ver==79) { 48 | ver <- "79.0.3945.36" 49 | } else if(chrome_ver==78) { 50 | ver <- "78.0.3904.70" 51 | } else if(chrome_ver==77) { 52 | ver <- "77.0.3865.40" 53 | } else if(chrome_ver==76) { 54 | ver <- "76.0.3809.126" 55 | } else if(chrome_ver==75) { 56 | ver <- "75.0.3770.140" 57 | } else if(chrome_ver==74) { 58 | ver <- "74.0.3729.6" 59 | } else if(chrome_ver==73) { 60 | ver <- "73.0.3683.68" 61 | } else { 62 | stop("Invalid chrome version. fbSim supports Chrome 73 or higher.",call.=FALSE) 63 | } 64 | 65 | 66 | #=============================================================== 67 | #### loads the right version of chromedriver 68 | #### and passes the profile options. It creates the folder 69 | #### 70 | cDrv <- wdman::chrome(version = ver, verbose = FALSE, check = TRUE) 71 | eCaps <- RSelenium::getChromeProfile(dataDir = user_path, 72 | profileDir = "Profile1") 73 | eCaps$chromeOptions$args[[3]] <- "--disable-notifications" 74 | # eCaps$chromeOptions$args[[4]] <- "--headless" 75 | remDr <- RSelenium::remoteDriver(remoteServerAddr = "localhost", 76 | browserName = "chrome", 77 | port = 4567L, 78 | extraCapabilities = eCaps) 79 | #=============================================================== 80 | 81 | #=============================================================== 82 | ### The browser goes into Facebook main page and logs in 83 | ### With the new fb policy infos are automatically saved in the profile folder 84 | ### which should be created in the folder indicated as argument. 85 | 86 | pass <- getPass::getPass("Enter your Facebook profile's password: ") 87 | 88 | tryCatch({ 89 | suppressMessages({ 90 | remDr$open() 91 | remDr$navigate("http://www.facebook.com") 92 | 93 | }) 94 | }, 95 | error = function(e) { 96 | remDr$close() 97 | cDrv$stop() 98 | stop("something went wrong. Check your internet connection and try again.", call.=FALSE) 99 | 100 | } 101 | ) 102 | 103 | tryCatch({ 104 | suppressMessages({ 105 | remDr$findElement("name", "email")$sendKeysToElement(list(user)) 106 | remDr$findElement("name", "pass")$sendKeysToElement(list(pass)) 107 | if(length(remDr$findElements("id", "loginbutton"))>0) { 108 | remDr$findElements("id", "loginbutton")[[1]]$clickElement()} 109 | else { 110 | remDr$findElements("name", "login")[[1]]$clickElement() 111 | } 112 | remDr$executeScript("return document.readyState == 'complete';") #wait until the page loaded, not sure if works 113 | Sys.sleep(15) 114 | }) 115 | }, 116 | error = function(e) { 117 | warning(paste0("the account has already been set! Please delete the folder in ", 118 | user_path, 119 | " to set it again"), 120 | call. = FALSE) 121 | 122 | } 123 | ) 124 | 125 | string <- remDr$getCurrentUrl()[[1]] 126 | if (grepl("login_attempt=", string)) { 127 | 128 | remDr$close() 129 | cDrv$stop() 130 | stop("something went wrong. Check your e-mail and password and try again.", 131 | call. = FALSE) 132 | 133 | } 134 | else { 135 | # Close ports 136 | remDr$close() 137 | cDrv$stop() 138 | } 139 | 140 | #=============================================================== 141 | 142 | 143 | } -------------------------------------------------------------------------------- /R/fbSimLikes.R: -------------------------------------------------------------------------------- 1 | #' Show pages that are liked by a public Facebook page and stores them in a data frame 2 | #' 3 | #' Show posts of a public Facebook page, by returning a data frame in which are collected the name of the page and the identifier. 4 | #' The function needs a valid profile Chrome folder (see \code{fbSetAccount} for more information) 5 | #' 6 | #' @param page_id The public likes of the Fb page to be shown. 7 | #' @param user_path The location of the profile folder (folder name included). 8 | #' @param chrome_ver The installed version of Google Chrome. To get the Chrome version go to chrome://version in Chrome's address bar and use the first two digits - e.g. if the version is 73.0.3683.86, just use 73). 9 | #' 10 | #' 11 | #' @return A dataframe with information on public pages. 12 | #' @author Moreno Mancosu \email{moreno.mancosu@@carloalberto.org}, Federico Vegetti \email{vegetti.fede@@gmail.com} 13 | #' 14 | #' @seealso \code{\link{setFbAccount}} 15 | #' 16 | #' @examples 17 | #' page_id <- "116716651695782" #Silvio Berlusconi's official page ID 18 | #' user_path <- "C:/Users/Username/Desktop/Chrome_profile" 19 | #' data <- fbSimLikes(user_path, page_id) 20 | #' 21 | #' @export 22 | #' 23 | 24 | fbSimLikes <- function(page_id, user_path, chrome_ver = 86) { 25 | 26 | 27 | #=============================================================== 28 | ### Error if missing argument(s) 29 | if (methods::missingArg(page_id) | methods::missingArg(user_path)) { 30 | stop("missing argument(s)",call.=FALSE) 31 | } 32 | 33 | #### 34 | 35 | ver <- "86.0.4240.22" 36 | if(chrome_ver==86) { 37 | ver <- "86.0.4240.22" 38 | } else if(chrome_ver==85) { 39 | ver <- "85.0.4183.87" 40 | } else if(chrome_ver==84) { 41 | ver <- "84.0.4147.30" 42 | } else if(chrome_ver==83) { 43 | ver <- "83.0.4103.39" 44 | } else if(chrome_ver==81) { 45 | ver <- "81.0.4044.138" 46 | } else if(chrome_ver==80) { 47 | ver <- "80.0.3987.106" 48 | } else if(chrome_ver==79) { 49 | ver <- " 79.0.3945.36" 50 | } else if(chrome_ver==78) { 51 | ver <- "78.0.3904.70" 52 | } else if(chrome_ver==77) { 53 | ver <- "77.0.3865.40" 54 | } else if(chrome_ver==76) { 55 | ver <- "76.0.3809.126" 56 | } else if(chrome_ver==75) { 57 | ver <- "75.0.3770.140" 58 | } else if(chrome_ver==74) { 59 | ver <- "74.0.3729.6" 60 | } else if(chrome_ver==73) { 61 | ver <- "73.0.3683.68" 62 | } else { 63 | stop("Invalid chrome version. fbSim supports Chrome 73 or higher.",call.=FALSE) 64 | } 65 | 66 | 67 | 68 | #=============================================================== 69 | #### loads the right version of chromedriver 70 | #### and passes the profile options. It creates the folder 71 | #### 72 | cDrv <- wdman::chrome(version = ver, verbose = FALSE, check = TRUE) 73 | 74 | eCaps <- RSelenium::getChromeProfile(dataDir = user_path, 75 | profileDir = "Profile1") 76 | eCaps$chromeOptions$args[[3]] <- "--disable-notifications" 77 | # eCaps$chromeOptions$args[[4]] <- "--headless" 78 | # if( minimal==TRUE) { 79 | # eCaps$chromeOptions$args[[5]] <- "--window-position=20,20" 80 | # eCaps$chromeOptions$args[[6]] <- "--window-size=20,20" 81 | # } 82 | remDr<- RSelenium::remoteDriver(remoteServerAddr = "localhost", 83 | browserName = "chrome", 84 | port = 4567L, 85 | extraCapabilities = eCaps) 86 | 87 | #========================================== 88 | #========== FROM UID TO ID ================ 89 | 90 | ### Opens a session and goes to the chosen page 91 | remDr$open() 92 | url_id <- paste0("https://m.facebook.com/", page_id) 93 | 94 | tryCatch({ 95 | remDr$navigate(url_id) 96 | }, 97 | error = function(e) { 98 | remDr$close() 99 | cDrv$stop() 100 | stop("something went wrong. Check your internet connection and try again.",call.=FALSE) 101 | 102 | } 103 | ) 104 | 105 | if(length(remDr$findElements(using = 'id', 'mobile_login_bar')) > 0) { 106 | 107 | remDr$close() 108 | cDrv$stop() 109 | stop("you are not logged in. Please run fbSetAccount and try again.", 110 | call. = FALSE) 111 | 112 | } 113 | 114 | var <- remDr$findElements(using = 'xpath', '//form[@method="post"]') 115 | elemtxt <- var[[1]]$getElementAttribute("outerHTML")[[1]] 116 | elemxml <- XML::htmlTreeParse(elemtxt, useInternalNodes = T, encoding = "UTF-8") 117 | 118 | uid <- gsub("^.*?id=", "", elemtxt) 119 | uid <- gsub("\\\" .*$", "", uid) 120 | 121 | #=============================================================== 122 | ### FANS 123 | ### Opens a session and goes to the chosen page 124 | #remDr$open() 125 | url_id <- paste0("https://www.facebook.com/browse/fanned_pages/?id=", uid) 126 | 127 | tryCatch({ 128 | remDr$navigate(url_id) 129 | }, 130 | error = function(e) { 131 | remDr$close() 132 | cDrv$stop() 133 | stop("something went wrong. Check your internet connection and try again.",call.=FALSE) 134 | 135 | } 136 | ) 137 | 138 | #### PARSING 139 | 140 | var <- remDr$findElements(using = 'xpath', '//li[@class="fbProfileBrowserListItem"]') 141 | 142 | if(length(var) == 0) { 143 | print("No pages liked by the selected page.") 144 | break 145 | } else { 146 | link_data <- data.frame(page_id = 0, 147 | page_name = 0, 148 | stringsAsFactors = FALSE) 149 | 150 | for(i in 1:length(var)) { 151 | 152 | elemtxt <- var[[i]]$getElementAttribute("outerHTML")[[1]] ####CHANGE COUNTER 153 | elemxml <- XML::htmlTreeParse(elemtxt, useInternalNodes = T, encoding = "UTF-8") 154 | 155 | page_name <- XML::xpathSApply(elemxml, "//a", XML::xmlValue) 156 | page_name <- page_name[2] 157 | ### page_id 158 | 159 | page_id <- XML::xpathSApply(elemxml, "//a", XML::xmlAttrs) 160 | page_id <- gsub("^.*facebook.com/","",page_id[1]) 161 | page_id <- gsub("/.*$","",page_id) 162 | 163 | link_data[i,] <- "NA" 164 | link_data$page_name[i] <- page_name 165 | link_data$page_id[i] <- page_id 166 | } 167 | } 168 | 169 | remDr$close() 170 | cDrv$stop() 171 | 172 | # Return data 173 | return(link_data) 174 | } 175 | -------------------------------------------------------------------------------- /R/fbSimPosts.R: -------------------------------------------------------------------------------- 1 | #' Show posts of a public Facebook page and stores some information in a dataframe 2 | #' 3 | #' Show posts of a public Facebook page, by returning a data frame in which are collected the text of the post, the unique identifier, an indicator of whether the post is pinned or not, number of reactions, likes, shares, and comments. 4 | #' The function needs a valid profile Chrome folder (see \code{fbSetAccount} for more information) 5 | #' 6 | #' @param page_id The public Fb page to be shown. 7 | #' @param user_path The location of the profile folder (folder name included). 8 | #' @param n_posts The number of posts to be shown (from the most recent to the oldest) 9 | #' @param timeout The system timeout between a browser action and the other. Default is c(3, 6), namely a random time between 3 and 6 seconds. 10 | #' @param chrome_ver The installed version of Google Chrome. To get the Chrome version go to chrome://version in Chrome's address bar and use the first two digits - e.g. if the version is 73.0.3683.86, just use 73). 11 | #' 12 | #' 13 | #' @return A dataframe with information on public posts. 14 | #' @author Moreno Mancosu \email{moreno.mancosu@@carloalberto.org}, Federico Vegetti \email{vegetti.fede@@gmail.com} 15 | #' 16 | #' @seealso \code{\link{setFbAccount}} 17 | #' 18 | #' @examples 19 | #' page_id <- "116716651695782" #Silvio Berlusconi's official page ID 20 | #' user_path <- "C:/Users/Username/Desktop/Chrome_profile" 21 | #' data <- fbSimPosts(user_path, page_id, n_posts = 10) 22 | #' 23 | #' @export 24 | #' 25 | 26 | fbSimPosts <- function(page_id, user_path, n_posts = 25, timeout = c(3, 6), chrome_ver = 86) { 27 | 28 | #=============================================================== 29 | ### Error if missing argument(s) 30 | 31 | ### Error if missing argument(s) 32 | if (methods::missingArg(page_id) | methods::missingArg(user_path)) { 33 | stop("missing argument(s)",call.=FALSE) 34 | } 35 | 36 | #### 37 | 38 | ver <- "86.0.4240.22" 39 | if(chrome_ver==86) { 40 | ver <- "86.0.4240.22" 41 | } else if(chrome_ver==85) { 42 | ver <- "85.0.4183.87" 43 | } else if(chrome_ver==84) { 44 | ver <- "84.0.4147.30" 45 | } else if(chrome_ver==83) { 46 | ver <- "83.0.4103.39" 47 | } else if(chrome_ver==81) { 48 | ver <- "81.0.4044.138" 49 | } else if(chrome_ver==80) { 50 | ver <- "80.0.3987.106" 51 | } else if(chrome_ver==79) { 52 | ver <- "79.0.3945.36" 53 | } else if(chrome_ver==78) { 54 | ver <- "78.0.3904.70" 55 | } else if(chrome_ver==77) { 56 | ver <- "77.0.3865.40" 57 | } else if(chrome_ver==76) { 58 | ver <- "76.0.3809.126" 59 | } else if(chrome_ver==75) { 60 | ver <- "75.0.3770.140" 61 | } else if(chrome_ver==74) { 62 | ver <- "74.0.3729.6" 63 | } else if(chrome_ver==73) { 64 | ver <- "73.0.3683.68" 65 | } else { 66 | stop("Invalid chrome version. fbSim supports Chrome 73 or higher.",call.=FALSE) 67 | } 68 | 69 | 70 | #============================================================================================ 71 | 72 | #============================================================ 73 | # Deletes the folder for the profile in case is already there 74 | # if(dir.exists(user_path)) unlink(user_path, recursive = T) 75 | #============================================================ 76 | 77 | #=============================================================== 78 | #### loads the right version of chromedriver 79 | #### and passes the profile options. It creates the folder 80 | #### 81 | cDrv <- wdman::chrome(version = ver, verbose = FALSE, check = TRUE) 82 | eCaps <- RSelenium::getChromeProfile(dataDir = user_path, 83 | profileDir = "Profile1") 84 | eCaps$chromeOptions$args[[3]] <- "--disable-notifications" 85 | # eCaps$chromeOptions$args[[4]] <- "--headless" 86 | # if( minimal==TRUE) { 87 | # eCaps$chromeOptions$args[[5]] <- "--window-position=20,20" 88 | # eCaps$chromeOptions$args[[6]] <- "--window-size=20,20" 89 | # } 90 | remDr<- RSelenium::remoteDriver(remoteServerAddr = "localhost", 91 | browserName = "chrome", 92 | port = 4567L, 93 | extraCapabilities = eCaps) 94 | #=============================================================== 95 | 96 | ### Opens a session and goes to the chosen page 97 | remDr$open() 98 | url_id <- paste0("https://m.facebook.com/", page_id) 99 | 100 | tryCatch({ 101 | remDr$navigate(url_id) 102 | }, 103 | error = function(e) { 104 | remDr$close() 105 | cDrv$stop() 106 | stop("something went wrong. Check your internet connection and try again.",call.=FALSE) 107 | 108 | } 109 | ) 110 | 111 | if(length(remDr$findElements(using = 'id', 'mobile_login_bar')) > 0) { 112 | 113 | remDr$close() 114 | cDrv$stop() 115 | stop("you are not logged in. Please run fbSetAccount and try again.", 116 | call. = FALSE) 117 | 118 | } 119 | 120 | repeat { 121 | 122 | ################# RESTART FROM HERE 123 | 124 | ### The m. does not contain any post, we must go down for a while (usually 3 times) 125 | 126 | for (i in 1:3) { 127 | webElem <- remDr$findElement("css", "body") 128 | webElem$sendKeysToElement(list(key = "end")) 129 | Sys.sleep(stats::runif(1, min = min(timeout), max = max(timeout))) 130 | } 131 | 132 | var <- remDr$findElements(using = 'xpath', '//div[@class="_3drp"]') 133 | 134 | #### Since class _55wo _gui is also present in things that are not post, we have to erase it 135 | #### when it does not provide a correct post_id 136 | 137 | for(i in 1:length(var)) { 138 | 139 | elemtxt <- var[[i]]$getElementAttribute("outerHTML")[[1]] 140 | elemxml <- XML::htmlTreeParse(elemtxt, useInternalNodes = T, encoding = "UTF-8") 141 | 142 | page <- XML::xpathSApply(elemxml, "//article", XML::xmlGetAttr, "data-store") 143 | 144 | if(class(page)=="NULL"){ 145 | var <- var[-i] 146 | } 147 | } 148 | 149 | ###### if exp. number of posts not reached, repeat the loop 150 | 151 | if(length(var)<= n_posts) { 152 | print(length(var)) 153 | } 154 | else { 155 | print(n_posts) 156 | break 157 | } 158 | } 159 | 160 | #### PARSING 161 | 162 | #### creates df 163 | 164 | post_data <- data.frame(page_id = 0, 165 | post_id = 0, 166 | datetime = "", 167 | date_collect = 0, 168 | react = 0, 169 | comm = 0, 170 | shares = 0, 171 | pinned = 0, 172 | text_post = "", 173 | # text_orig = "", 174 | link = "", 175 | stringsAsFactors = FALSE) 176 | 177 | ##### parses post by post 178 | 179 | for (i in 1:n_posts) { 180 | 181 | #### FIRST POST 182 | 183 | elemtxt <- var[[i]]$getElementAttribute("outerHTML")[[1]] #####CAMBIA L'1 184 | elemxml <- XML::htmlTreeParse(elemtxt, useInternalNodes = T, encoding = "UTF-8") 185 | 186 | page <- XML::xpathSApply(elemxml, "//article", XML::xmlGetAttr, "data-store") 187 | 188 | ### POST_ID 189 | 190 | post_id <- gsub("^.*top_level_post_id.", "", page) 191 | post_id <- gsub(":tl_objid.*$", "", post_id) 192 | 193 | ### PAGE_ID 194 | 195 | page_id <- gsub("^.*:page_id.", "", page) 196 | page_id <- gsub(":page_insights..*$", "", page_id) 197 | page_id <- gsub(":photo_id..*$", "", page_id) 198 | page_id <- gsub("photo_attachments_list..*$", "", page_id) 199 | page_id <- gsub(":story_location..*$", "", page_id) 200 | page_id <- gsub(":", "", page_id) 201 | 202 | ### PUBLISH TIME 203 | 204 | datetime <- gsub("^.*publish_time\\\\\\\":", "", page) 205 | datetime <- gsub(",\\\\\\\"story_name.*$", "", datetime) 206 | datetime <- gsub(",\\\\\\\"object_fbtype.*$", "", datetime) 207 | 208 | ### REACTIONS 209 | 210 | react <- XML::xpathSApply(elemxml, "//div[@class='_1g06']", XML::xmlValue) 211 | react <- XML::xpathSApply(elemxml, "//div[@class='_1g06']", XML::xmlValue) 212 | if(length(react) > 0) { 213 | react <- gsub("^.* and ", "", react) 214 | react <- gsub(" others", "", react) 215 | react <- ifelse(grepl("K", react), as.numeric(sub("K", "", react))*1000, as.numeric(react)) 216 | 217 | } else { 218 | react <- 0 219 | } 220 | 221 | ### COMMENTS AND SHARES 222 | 223 | # commshare <- XML::xpathSApply(elemxml, "//div[@class='_1fnt']", XML::xmlValue) 224 | commshare <- XML::xpathSApply(elemxml, "//span[@class='_1j-c']", XML::xmlValue) 225 | commshare <- tolower(commshare) 226 | if(sum(grepl("comment", commshare)) == 0){ 227 | comm <- 0 228 | } else { 229 | comm <- gsub(" comment.*", "", commshare[grepl("comment", commshare)]) 230 | comm <- ifelse(grepl("k", comm), 231 | as.numeric(sub("k", "", comm))*1000, 232 | as.numeric(comm)) 233 | } 234 | if(sum(grepl("share", commshare)) == 0){ 235 | shares <- 0 236 | } else { 237 | shares <- gsub(" share.*", "", commshare[grepl("share", commshare)]) 238 | shares <- ifelse(grepl("k", shares), 239 | as.numeric(sub("k", "", shares))*1000, 240 | as.numeric(shares)) 241 | } 242 | 243 | ### IS_PINNED? 244 | 245 | pin <- XML::xpathSApply(elemxml, "//i[@class='img _4q4l img _2sxw']", XML::xmlValue) 246 | pinned <- ifelse(is.character(pin) == T,1,0) 247 | 248 | ### TEXT 249 | 250 | text <- XML::xpathSApply(elemxml, "//div[@class='_5rgt _5nk5 _5msi']", XML::xmlValue) 251 | text <- sapply(text, function(x) gsub("… More", "", x)) 252 | if(length(text) >= 1) { 253 | text_post <- text[1] 254 | # text_orig <- text[2] 255 | } else { 256 | text_post <- "" 257 | # text_orig <- "" 258 | } 259 | text <- sub("See Translation", "", text) 260 | 261 | ### LINK 262 | 263 | link_prov <- XML::xpathSApply(elemxml, "//a[@class='touchable _4qxt']", XML::xmlAttrs) 264 | if(length(link_prov) > 0) { 265 | link <- URLdecode(link_prov[3]) 266 | link <- gsub("https://lm.facebook.com/l.php\\?u=","",link) 267 | link <- gsub("\\?fbclid=.*$","",link) 268 | } else { 269 | link <- "" 270 | } 271 | 272 | ### POPULATE DATASET 273 | 274 | post_data[i,] <- "NA" 275 | post_data$page_id[i] <- page_id 276 | post_data$post_id[i] <- post_id 277 | post_data$datetime[i] <- datetime 278 | post_data$react[i] <- react 279 | post_data$comm[i] <- comm 280 | post_data$shares[i] <- shares 281 | post_data$pinned[i] <- pinned 282 | post_data$text_post[i] <- text_post 283 | # post_data$text_orig[i] <- text_orig 284 | post_data$link[i] <- link 285 | post_data$date_collect[i] <- as.character(Sys.time()) 286 | 287 | } 288 | 289 | # Convert date 290 | post_data$datetime <- anytime::anytime(as.numeric(post_data$datetime)) 291 | 292 | remDr$close() 293 | cDrv$stop() 294 | 295 | # Return data 296 | return(post_data) 297 | } 298 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # An introduction to the ```fbSim``` package 3 | 4 | *Moreno Mancosu and Federico Vegetti* 5 | 6 | 7 | ```fbSim``` is an ```R``` package which simulates the behavior of a registered user on Facebook, by using an automatic browsing approach. It includes a series of functions to allow ```R``` users to automatically browse a public Facebook page and collect information on the page's posts. The type of information collected is similar to what could be obtained using [Netvizz](https://wiki.digitalmethods.net/Dmi/ToolNetvizz) (RIP) until September 4th, 2019. This brief tutorial introduces the basic functions of the library, and describes how to make the package work. 8 | 9 | ## System requirements 10 | 11 | ```fbSim``` depends on Google Chrome. The package has been tested with Chrome version ```80.x```, but it is possible to change Chrome version (```fbSim``` supports Chrome version ```73.x``` or later, see below). You can check your version of Chrome by typing the following line in the browser's address bar: 12 | 13 | ```{bash eval = FALSE} 14 | chrome://version/ 15 | ``` 16 | 17 | ## Installation 18 | 19 | You can install ```fbSim``` either by using the function ```install_github()``` or the function ```install()``` (both from the package ```devtools```) on a downloaded archive. In the first case, you can install ```fbSim``` by typing: 20 | 21 | ```r 22 | library(devtools) 23 | 24 | devtools::install_github("morenomancosu/fbSim") 25 | ``` 26 | 27 | In case you have cloned the package from this repository (usually ```fbSim-master.zip```) you can install it by unzipping it and typing: 28 | 29 | ```r 30 | library(devtools) 31 | 32 | devtools::install("path/to/file/fbSim-master", dependencies = TRUE) 33 | ``` 34 | 35 | ## Initial checks 36 | 37 | Unlike similar packages such as [```RFacebook```](https://cran.r-project.org/web/packages/Rfacebook/Rfacebook.pdf), ```fbSim``` does not need the user to provide an access token, but instead it needs the e-mail address and password associated to a valid Facebook profile. 38 | 39 | Note that, for the package to work correctly, the language of Facebook interface must be **English**. You can change the interface by going to the "Language" settings [here](https://www.facebook.com/settings?tab=language). 40 | 41 | 42 | ## Authentication: ```fbSetAccount``` 43 | 44 | The function ```fbSetAccount``` allows to produce a new Chrome profile with your Facebook credentials stored in it. Producing a new user does not change in any way your normal Chrome usage. The function does not store any object in ```R``` workspace, but creates a folder containing profile information (including the encrypted Facebook ID and password) in a format that Chrome understands. The syntax works as follows: 45 | 46 | ```r 47 | user <- "user@domain.org" 48 | user_path <- "C:/Users/Username/Desktop/Chrome_profile" 49 | fbSetAccount(user, user_path) 50 | ``` 51 | 52 | In the code above, the function creates a folder where the profile information is stored. We highly reccomend providing the entire path to the folder instead of just the name of the folder (e.g. for a Windows user, ```C:/Users/Username/Desktop/Chrome_profile``` is better than just ```Chrome_profile```). Before producing the folder, you will be asked to enter your Facebook password. 53 | 54 | Once you created the folder, the same Chrome profile will be used by all the other functions of ```fbSim```. The profile is permanent, and there is no need to refresh it (as in the case of old access tokens in ```RFacebook```). For this reason, we reccomand **not** to delete the folder, and to use it for all other sessions. 55 | 56 | **Important**: If any function of ```fbSim``` returns the error "version requested doesn't match versions available", you probably have issues with your version of Chrome. If the version of Chrome on your computer is older than ``80.x```, you can change the version by adding the option ```chrome_ver = xx``` (where ```xx``` is replaced by the first two digits of your Chrome version). ```fbSim``` supports Chrome ```73.x``` or newer. 57 | 58 | ## Navigate Facebook public posts in a page: ```fbSimPosts``` 59 | 60 | The function ```fbSimPosts``` allows you to navigate and get information about the posts from a target public Facebook page. The function needs the user to insert as argument the Facebook ID of the page (this can be obtained e.g. on [https://findmyfbid.com/](https://findmyfbid.com/)) or the UID (non-numeric identifier) of the page. In addition, the full path to a valid Chrome profile folder that contains the encrypted user email and password (produced with ```fbSetAccount```) must be provided. Other additional arguments of the function are: 61 | 62 | - The number of posts to be automatically navigated (default is 25). 63 | - The boundaries of the ```timeout``` between a request and the other (in seconds). Tests on the routine have found that a timeout going from 3 to 6 seconds is sufficiently slow not to overflow Facebook with requests (too frequent requests might prompt Facebook to block your account because of an attempt of DDoS). 64 | 65 | In the following example, we navigate the last 25 posts from Silvio Berlusconi's Facebook page. 66 | 67 | ```r 68 | page_id <- "SilvioBerlusconi" # Silvio Berlusconi's page UID 69 | user_path <- "C:/Users/Username/Desktop/Chrome_profile" 70 | posts <- fbSimPosts(page_id, user_path, n_posts = 25, timeout = c(3, 6)) 71 | ``` 72 | 73 | The function ```fbSimPosts``` produces a ```data.frame``` containing the following variables: 74 | 75 | - ```page_id```: the ID of the target page (the same as the input argument). 76 | - ```post_id```: the ID of the post, which can be used to access the post itself via web browser. 77 | - ```datetime```: the date and time when the post was published. 78 | - ```react```: the approximate number of reactions to the post. 79 | - ```comm```: the approximate number of comments to the post. 80 | - ```shares```: the approximate number of times the post was shared by other users. 81 | - ```pinned```: a variable that is 1 when the post is "pinned" and 0 otherwise. 82 | - ```text_post```: the textual content of the post. 83 | - ```link```: in case another post/webpage is linked, the link which the post directs to. 84 | - ```date_collect```: the date and time when the post was collected. 85 | 86 | 87 | ## Navigate the pages liked by a page: ```fbSimLikes``` 88 | 89 | The function ```fbSimLikes``` allows to navigate and get information about the pages liked by a target Facebook page. As in ```fbSimPosts```, the function accepts as arguments the Facebook ID or UID of the target page, as well as the path to a valid Chrome profile folder that contains the encrypted user email and password (produced with ```fbSetAccount```). 90 | 91 | In the following example, we navigate the pages liked by Silvio Berlusconi's page. ```fbSimLikes``` accepts either the ID (numeric identifier) or the UID (non-numeric identifier) of the page, and returns the UID of the liked pages. 92 | 93 | ```r 94 | page_id <- "SilvioBerlusconi" # Silvio Berlusconi's official page UID 95 | user_path <- "C:/Users/Username/Desktop/Chrome_profile" 96 | likedpages <- fbSimLikes(page_id, user_path) 97 | ``` 98 | 99 | The function ```fbSimLikes``` produces a ```data.frame``` containing the following variables: 100 | 101 | - ```page_name```: the name of the pages liked by the target page. 102 | - ```page_id```: the UID of the pages liked by the target page. 103 | -------------------------------------------------------------------------------- /fbSim.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 4 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | BuildType: Package 16 | PackageUseDevtools: Yes 17 | PackageInstallArgs: --no-multiarch --with-keep.source 18 | PackageRoxygenize: rd,collate,namespace 19 | -------------------------------------------------------------------------------- /man/fbSetAccount.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fbSetAccount.R 3 | \name{fbSetAccount} 4 | \alias{fbSetAccount} 5 | \title{Set a (permanent) Fb account} 6 | \usage{ 7 | fbSetAccount(user, user_path = "Chrome_profile", chrome_ver = 77) 8 | } 9 | \arguments{ 10 | \item{user}{Your Facebook e-mail (The Fb password is requested once the function is called).} 11 | 12 | \item{user_path}{The location of the folder (folder name included).} 13 | 14 | \item{chrome_ver}{The installed version of Google Chrome. To get the Chrome version go to chrome://version in Chrome's address bar and use the first two digits - e.g. if the version is 73.0.3683.86, just use 73).} 15 | } 16 | \value{ 17 | A folder in \code{"user_path"} containing a Chrome profile ready to access to Facebook. 18 | } 19 | \description{ 20 | Produces a folder containing Chrome profile information and saved Fb password and email 21 | } 22 | \examples{ 23 | user <- "user@domain.org" 24 | user_path <- "C:/Users/Username/Desktop/Chrome_profile" 25 | fbSetAccount(user, user_path) 26 | 27 | } 28 | \author{ 29 | Moreno Mancosu \email{moreno.mancosu@carloalberto.org}, Federico Vegetti \email{vegetti.fede@gmail.com} 30 | } 31 | -------------------------------------------------------------------------------- /man/fbSimLikes.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fbSimLikes.R 3 | \name{fbSimLikes} 4 | \alias{fbSimLikes} 5 | \title{Show pages that are liked by a public Facebook page and stores them in a data frame} 6 | \usage{ 7 | fbSimLikes(page_id, user_path, chrome_ver = 77) 8 | } 9 | \arguments{ 10 | \item{page_id}{The public likes of the Fb page to be shown.} 11 | 12 | \item{user_path}{The location of the profile folder (folder name included).} 13 | 14 | \item{chrome_ver}{The installed version of Google Chrome. To get the Chrome version go to chrome://version in Chrome's address bar and use the first two digits - e.g. if the version is 73.0.3683.86, just use 73).} 15 | } 16 | \value{ 17 | A dataframe with information on public pages. 18 | } 19 | \description{ 20 | Show posts of a public Facebook page, by returning a data frame in which are collected the name of the page and the identifier. 21 | The function needs a valid profile Chrome folder (see \code{fbSetAccount} for more information) 22 | } 23 | \examples{ 24 | page_id <- "116716651695782" #Silvio Berlusconi's official page ID 25 | user_path <- "C:/Users/Username/Desktop/Chrome_profile" 26 | data <- fbSimLikes(user_path, page_id) 27 | 28 | } 29 | \seealso{ 30 | \code{\link{setFbAccount}} 31 | } 32 | \author{ 33 | Moreno Mancosu \email{moreno.mancosu@carloalberto.org}, Federico Vegetti \email{vegetti.fede@gmail.com} 34 | } 35 | -------------------------------------------------------------------------------- /man/fbSimPosts.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fbSimPosts.R 3 | \name{fbSimPosts} 4 | \alias{fbSimPosts} 5 | \title{Show posts of a public Facebook page and stores some information in a dataframe} 6 | \usage{ 7 | fbSimPosts(page_id, user_path, n_posts = 25, timeout = c(3, 6), 8 | chrome_ver = 77) 9 | } 10 | \arguments{ 11 | \item{page_id}{The public Fb page to be shown.} 12 | 13 | \item{user_path}{The location of the profile folder (folder name included).} 14 | 15 | \item{n_posts}{The number of posts to be shown (from the most recent to the oldest)} 16 | 17 | \item{timeout}{The system timeout between a browser action and the other. Default is c(3, 6), namely a random time between 3 and 6 seconds.} 18 | 19 | \item{chrome_ver}{The installed version of Google Chrome. To get the Chrome version go to chrome://version in Chrome's address bar and use the first two digits - e.g. if the version is 73.0.3683.86, just use 73).} 20 | } 21 | \value{ 22 | A dataframe with information on public posts. 23 | } 24 | \description{ 25 | Show posts of a public Facebook page, by returning a data frame in which are collected the text of the post, the unique identifier, an indicator of whether the post is pinned or not, number of reactions, likes, shares, and comments. 26 | The function needs a valid profile Chrome folder (see \code{fbSetAccount} for more information) 27 | } 28 | \examples{ 29 | page_id <- "116716651695782" #Silvio Berlusconi's official page ID 30 | user_path <- "C:/Users/Username/Desktop/Chrome_profile" 31 | data <- fbSimPosts(user_path, page_id, n_posts = 10) 32 | 33 | } 34 | \seealso{ 35 | \code{\link{setFbAccount}} 36 | } 37 | \author{ 38 | Moreno Mancosu \email{moreno.mancosu@carloalberto.org}, Federico Vegetti \email{vegetti.fede@gmail.com} 39 | } 40 | --------------------------------------------------------------------------------