facebook R

Update: One good and one bad news: Finally the Rfacebook packaged got updated and is now compatible with the Facebook-API version 2. But this also means that it has to apply to the new restrictions of this version and so a lot of cool functions don´t work anymore.

Hello everybody! Today I found something very cool: There is a R package for mining Facebook. For Twitter there are several, but this is the first one really working well with Facebook. So I wanted to test it and was amazed about how easy it works.

Setup:

First we have to create an App on the Facebook platform. We will use this app to connect to the Facebook API. This way you can manage your connections very good but it also has some disadvantages. Different than in version 1 of the API you can now just get information of the friends who are also using the app. This creates big problems as you can´t create a friend network with all you friends anymore.

To create a new app go to https://developers.facebook.com

Facebook R create App

Click on “Apps” and choose “Add a New App“. In the next window choose “Website” and give your app a fancy name.

Facebook R name App

After clicking on “Create a New App ID“, choose a category for your app in the next window and apply the changes with “Create App ID“.

You can then click on “Skip Quick Start” to get directly to the settings of your app.

Facebook R skip quickstart

Facebook R app settings

Welcome to your first own Facebook app!

R

First we need to install the packages Rfacebook from github as thiss is currently the most recent version 0.5.

Ok now we need to connect our R session with our test app and authenticate it to our Facebook Profile for Data Mining. Rfacebook offers a very easy function for that.

Just copy your app id and your app secret from your app settings on the Facebook developer page.

The console will then print you the message:

Facebook R message

Copy the URL and go to the settings of your Facebook app. Click on the settings tab on the left side and then choose “+ Add Platform“.

R Facebook settings tab

Then add the URL in the field “Site URL” and save the changes.

Facebook R add url

Go back to your R session and hit enter. Then a browser window should open you have to allow the app to access your Facebook account.

If everything worked the browser should show the message

Facebook R success

And your R console will confirm it with

Facebook R success console

You can then save your fb_oauth object and use it for the next time.

 

Analyze Facebook with R!

Now we connected everything and have access to Facebook. We will start with getting our own profile information.

As I mentioned before because of Facebook´s new API policies the information you can get is very limited compared to the amount you were able to download with apps using API 1.

So I will just show you now how to get your own personal information but other posts will follow with new use-cases of the new API version.

The getUsers function returns public information about one or more Facebook user. If we use “me” as the username argument, it will return our own profile info.

Now we saved our own public information in the variable „me“ and you can take a look at it.

An advantage of the new API version is that you can get more than 100 likes. You can get the things you liked with:

 

Questions?

If you have any questions feel free to ask me on Twitter or write a comment here.

  • https://plus.google.com/102584768922430524677 Stephen Martin

    I’m not sure why, but I followed these steps and could not get the OAuth to work properly.
    The developer settings seem right, I authenticate through facebook, it says that I’m authenticated, and fbOAuth continues on.
    My auth object is just a list with a function in it, and when I use it as a token, it doesn’t work (Error in callAPI(query, token) :
    An active access token must be used to query information about the current user)

    Using the 2 hr token works fine though. Any ideas?

    • http://thinktostart.wordpress.com julianhi

      Hey Stephen,
      I don´t really know why it doesn´t work for you. I´m new to the Rfacebook package as well. But I´ll take a look at it

  • Pingback: Retreiving and analyzing Facebook data with R « Matteo Redaelli()

  • http://www.redaelli.org/matteo/ Matteo

    Nice! thanks

  • http://blog.revolutionanalytics.com David Smith

    I’m having the same issues as Stephen — my token always generates the error “An active access token must be used to query information about the current user”.

    • http://thinktostart.wordpress.com julianhi

      Hey David,
      I noticed that there seems to be a small problem during the authentication process, when Facebook tries to send the answer the OAuth details to the local web server. Did your web browser say: “Authentication complete — you can now close this page and return to R” ? When you approved the app to access your profile

  • http://www.dziennikarz.pl sms1962

    I’ve same problem as David. In my browser tab there is “Authentication complete — you can now close this page and return to R”. What I saw is that in my R console there is “Authentication complete” but there ins’t “Authentication successful”. I’dont know why, but any querry I do doesn’t work

    • http://thinktostart.wordpress.com julianhi

      Hey sms1962,
      The problem seems to occur if you press the “Any Key” too fast. You should wait a few minutes as the servers need some time.
      I think this could be also your problem.
      I´ll check it and put a note in my tutorial

      I hope i could help you.

      Regards
      Julian

  • http://blog.revolutionanalytics.com David Smith

    Yes, I do get the message “Authentication complete — you can now close this page and return to R”, but the token still seems like it doesn’t work.

    I used the command fb_oauth <- fbOAuth(app_id="app_id", app_secret="app_secret") to generate the token (which appeared to work fine), but in your post you said "I use an app for the authentication" — perhaps that's the difference?

  • http://blog.revolutionanalytics.com David Smith

    Hmm, I just tried it again and it seems to be working this time. I did leave a little bit of extra time before the “press any key” step (there was a message about it taking several minutes for the change to propagate to servers). Perhaps that was the difference.

    • http://thinktostart.wordpress.com julianhi

      Hey David
      It´s good that it is working for you now but that´s an important aspect as i heard that there are several persons with this problem. I´ll place a note in my tutorial.
      Thanks for your help David.

      Regards
      Julian

  • Tim

    I had to change my primary browser to IE (from Firefox) and then everything worked fine

    • http://thinktostart.wordpress.com julianhi

      Hey Tim
      im glad it is now working for you.
      But at your first tries: did you use your primary browser to connect with the app?

      Regards

  • Tim

    sure did (FF 25.0) and my R (3.02) just froze. For twitteR FF and R work fine but R studio chokes. The oauth seems to be the issue in both cases.

  • Pingback: Social Circle Visualization | Amy Hanlon()

  • http://www.dziennikarz.pl sms1962

    @julianhi Thx for you help. In my case, the problem was with R Studio, as @Tim write in comments. In R everything works as a charme, so I create fb_oauth in R and then use it with no problem in R Studio. IMO you should put info about this in your article.

    • http://thinktostart.wordpress.com julianhi

      Thanks for your info.
      I´ll put a hint in my tutorial.
      I didn´t test it with RStudio as i´m not a real fan of it 😉

      Regards

  • http://notebook.madsenlab.org Mark Madsen

    I can reliably replicate the problems folks have had with the latest (preview) version of RStudio. The oauth simply is not completing. It gives the “completed” but not the “successful” message. Running the auth token generator outside R studio worked just fine, and then you just proceed in RStudio as normal, loading the token from a file.

    • http://thinktostart.wordpress.com julianhi

      Hey Mark,
      thanks for your comment. I just added a hint in my tutorial.

      Regards
      Julian

  • Kan SJ

    After the fb_oauth <- fbOAuth(app_id="", app_secret="“) step, I see "Waiting for authentication in browser…" in the normal R session (not Rstudio) but it doesn't open any browser or do anything. When I run this in Rstudio, it does open up a tab in my default browser. Is there something I'm missing in my normal R session setup?

    • http://thinktostart.wordpress.com julianhi

      Hey Kan SJ
      sorry for my late answer.
      Do you use windows or mac?
      It is possible that the instance of the R framework, does not have to permission to open a browser windows.

      Regards

  • https://www.facebook.com/SALAMONASKA Salamon Aska

    fb_oauth <- fbOAuth(app_id="123456789", app_secret="1A2B3C4D“)
    app_secret="1A2B3C4D“)
    correct code mark "1A2B3C4D") not “

    • http://thinktostart.wordpress.com julianhi

      Hey Salamon Aska,
      thanks for your hint. I changed it in my tutorial.

      Regards

  • Alessandro

    Great post, thank you very much (I love step-by-step explanations!). Just added your blog to my RSS. 😉

    • http://thinktostart.wordpress.com julianhi

      Thank you Alessandro! I really like to hear that! It keeps me motivated!
      Regards
      Julian

  • satya

    is it any possible famous( it is public page) facebook user extraction using R tools

    • http://thinktostart.wordpress.com julianhi

      Hey satya,
      take a look at the following tutorial and scroll down to “Analyzing data from a Facebook page”. This should dp everything you want.

      Regards

  • Rafal

    Hey,
    Thanks! great article :)

    I search in help but I can’t find answer for my question:

    Is it possible to anlalize with this package fun_pages that uses clicks as “liked”?

    Once I used for this FQL:

    SELECT page_id,name, page_url
    FROM page
    WHERE page_id IN (
    SELECT page_id
    FROM page_fan
    WHERE uid IN
    (SELECT uid2 FROM friend WHERE uid1 = me()))

    thnx for any help with this :)

  • http://gravatar.com/ided idedided

    Hi Julianhi

    Thank for your tutorial. Really great and worked for me. Do you have, lets say guide book or anything exploring the FB API with R? Definitely it will be having possibilities to make great work. Thank in advance.
    Rgds

    • http://thinktostart.wordpress.com julianhi

      Hey idedided,
      at the moment you can´t use all API calls with the Rfacebook package. You can see here what calls are supported at the moment: http://cran.r-project.org/web/packages/Rfacebook/Rfacebook.pdf

      But i think a lot of calls will be added in the future. I hope i could help you.
      Regards

  • Pingback: » Big data in network analiza Facebooka V krizi smisla tiči misel()

  • http://gravatar.com/ided ided

    Hi julianhi

    Thank much. I got that. I’ve also tried some of the scripts in the tutorial. I wonder, can I retrieve or plot friend network? Using getNetwork I can plot my network but friends of mine?

    • http://thinktostart.wordpress.com julianhi

      Hi ided,
      it is not possible directly. Your friends would have to give access to the App and allow it to download their friends list. But for this you would have to do a lot of changes on the app.
      I hope i could help you.

      Regards

  • ided

    Thank you very much Juliahi

    That means I need friend’s API for doing that as mine?
    Have a great new year

    Thanks

    • http://thinktostart.wordpress.com julianhi

      You need your friend to grand access to the application. So give the application, you created, the right to download the private information.

      Regards

  • https://plus.google.com/+pankajraushan Pankaj Raushan

    Hi

    Ever time i try to authenticate by pasting site URL in Facebook, it gives an error as “something is wrong, we are working on it”

    Any help or comment on this type of error.

    Regards
    Pankaj

    • http://thinktostart.wordpress.com julianhi

      Hey Pankaj,
      I have this problem as well and also talked to somebody else who had this problem today. This seems to be caused by Facebook. There seems to be something wrong with their server. I will look if I can find a solution and will let you know.
      Regards

  • http://www.alessandroscocciapappagallo.com Alessandro

    Hi Julian,

    I have a “small” problem, I was wondering if you had any solution: I cannot create the app. Facebook says you need to be a verified developer. Point is, to be one you have to a) confirm your phone number or b) add your credit card details… And I have already done both. I also opened a ticket on Facebook about it: https://www.facebook.com/help/community/question/?id=10203002345927583&added and one on Stack Exchange: http://webapps.stackexchange.com/questions/54662/i-cannot-create-facebook-apps both with no luck. Any idea?

    • http://thinktostart.wordpress.com julianhi

      Hey Alessandro,
      there seem to be some heavy problems in the Facebook App Developer Center. I heard from a lot of people that they have problems. For example when they try to save the App an error message appears. I think Facebook is working on the Center and is doing some updates. I couldn´t think of another reason for all these problems.
      But I will follow your problem and hope that I can find a solution.

      Regards

      • http://www.alessandroscocciapappagallo.com Alessandro

        Thank you very much, Julian. Much appreciated.

        I think you’re right, apparently I am not the only one experiencing some problems. Yet, one would expect slightly more support/information from a company such as Facebook. Please, keep me updated if you find any solution.

        • http://thinktostart.wordpress.com julianhi

          Hey Alessandro,
          everything should work fine now. I can edit the settings again. How about you?
          Regards

  • https://www.facebook.com/rodrigo.alatorre.18 Rodrigo Alatorre

    Hi Julian, great blog you have here man!. I have 2 q’s:

    1) Using OAuth to connect with facebook, using pablobarbera / Rfacebook package to read facebook.
    the following example is extracted from the ?getPost doesnt work:

    #R Code
    fb_page <- getPage(page="facebook", token=fb_oauth)
    post n.l || n.comments > n.c) { :
    # missing value where TRUE/FALSE needed

    2) Im trying to read information on a fanpage (from someone else), you know friends list, likes. I saw someone asked for this, would you know how could i gain permission from that fanpage’s owner? I mean, he could actually give me administration rights, but still how could i tell GraphApi to query it, is there any “Add user” or “Add Page” to ask on GraphApi or App Configuration (OAuth) where i could achieve this?

    Just by answering any of the 2 q’s would be of high relevance for us

    • http://thinktostart.wordpress.com julianhi

      Hey Rodrigo,
      sorry for the late answer and thanks for your comment.
      1.) As far as I know you have to set a value for n in the getPage() function. Pablo suggests to set this number very high to make sure to get every single post. It should look like getPage(“facebook”, token, n=8000).
      Does this work for you?
      2.)You don´t really need this kind of permission. The getPage() function gives you access to the Page likes for example even if you are not the admin of the page. What information do you need from the fanpage?

      I hope I could help you a little bit.
      Regards

  • Aanchal Maheshwari

    Hi Julian,

    Your blog is very helpful for sophomores like me but I came across this problem :

    After giving this command. I get authentication complete but just after that I get the below mentioned error

    > fb_oauth <- fbOAuth(app_id="*********************", app_secret="**********************")

    Copy and paste into Site URL on Facebook App Settings: http://localhost:1410/
    When done, press any key to continue…
    starting httpd help server … done
    Waiting for authentication in browser…
    Authentication complete.
    Error in function (type, msg, asError = TRUE) : couldn't connect to host

    How should I rectify the above error ?

    • http://thinktostart.wordpress.com julianhi

      Hey Aanchal,
      Do you have some kind of firewall activated? Maybe you should turn it off and try again.
      Regards

  • Nahid hasan

    <- getUsers("me", token=fb_oauth)
    Error in callAPI(query, token) :
    An active access token must be used to query information about the current user.

    Why am I getting this error ? I try many times. but i didn't solve it. please help me out

    • http://thinktostart.wordpress.com julianhi

      Hey Nahid,
      could you please post the whole code you are using? It seems like there goes sth wrong when you get you auth token. It is just not valid anymore.

      Regards

  • http://twitter.com/Phil_Bi Debbie Philtjens (@Phil_Bi)

    Hi Julianhi,

    I tried to follow your description, but when I come to the part were you do the authentication. I don’t get the message that the authentication was successfull.

    I only get the following:

    > require(‘Rfacebook’)
    > fb_oauth <- fbOAuth(app_id=xxxxxxxxxxxxxxxxxxxxxxxx, app_secret=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)
    Copy and paste into Site URL on Facebook App Settings: xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    When done, press any key to continue…
    Loading required package: Rook
    Loading required package: tools
    Loading required package: brew
    Waiting for authentication in browser…
    Authentication complete.

    I get the messaga in my brower that the authentication was completed and that I can return to R. But there it stops.

    Can you please help me out?
    I tried it several times, but I don't see what I'm doing wrong.

    Thanks in advance!

    K regards,

    Debbie

    • http://thinktostart.wordpress.com julianhi

      Hey Debbie,
      so when you do auth step does there appear the browser window or is nothing happening?
      If the browser window appears with the URL in the URL bar and the page just doesn´t load, you normally just have to copy&paste the URL and hit enter again.

      Regards

  • Aanchal Maheshwari

    Thankyou very much Julian ! I did have firewall activated. Its working fine now :)

  • Nahid hasan

    thanks for your reply. and here is my code
    install.packages(“Rook”)
    install.packages(“Rfacebook”)

    require(c(“Rook”,”Rfacebook”))
    fb_oauth <- fbOAuth(app_id="176988012511120", app_secret="991efd8aba85c69235c4431b57dc12b8")

    save(fb_oauth, file="fb_oauth")
    load("fb_oauth2")
    me <- getUsers("me", token=fb_oauth)

    about 15 days ago i did it successfully. but after changing my fb password i lost my previous authentication. I open another apps. But this time I cant complete my steps. why i dont know. plz help me out.

    Note: and i have another little problem, i couldnt find the same page you mentioned in your screenshot(basic setting).
    thanks in advance

  • Nahid hasan

    hey !
    I just solved my problems….
    thanks and great post as well.

    • http://thinktostart.wordpress.com julianhi

      Hey Nahid,
      sorry for the late answer. How did you solve the problem?

      Regards

  • http://akileshr.blogspot.in Akilesh Radhakrishnan

    Hi Julian. Great article!

    When I use the getUsers() function, I get this: “An unknown error occurred. Querying too many users?”

    Any idea what I can do about that? Thanks.

    • http://thinktostart.wordpress.com julianhi

      Hey Akilesh,
      there is an easy answer: I think you are querying too many users.
      I think the rate limit is something like 100 users at once. If you want to query more users you should
      do it in several steps.
      Please let me know if this could solve your problem.

      Regards

  • Jaynal

    This is really nice… just tried and and working fine

  • Onkar Khaladkar

    Hi Julian
    Thanks for sharing this package.
    I’m having a problem to fetch comments from posts of a page.In the code I’m fetching a page and storing the details in fb_page1 and trying to fetch posts from that page(fb_page1). Further I need to fetch the comments for these posts which are fetched in newpost. I’m able to fetch the comments but in some cases
    1) where there are nested comments (like comments for a comment) the $comments_count value from the post is incorrect and I’m not able to fetch any value. The message is (data frame with 0 columns and 0 rows)
    2)It is considering the nested comments as a comment in $comments_count but in some cases it is not. So should we consider nested comments or ignore them.
    3) and i have observed that the comments are fetched only if the $comments_count is greater then 2 or 3 otherwise it gives a message
    (data frame with 0 columns and 0 rows).
    This is my code
    fb_page1 <- getPage(page="clubmahindra", token=fb_oauth)
    for(i in 1:nrow(fb_page1))
    {

    if(fb_page1$comments_count[i]!='0')
    {
    postid[length(postid)+1]<-fb_page1[i,7]
    post <- getPost(post=fb_page1[i,7], n=100, token=fb_oauth)
    newpost<-do.call(rbind.data.frame, post[3])
    }
    }
    This is what i observed might be wrong
    Regards

    • http://thinktostart.wordpress.com julianhi

      Hey Onkar Khaladkar,
      It seems like there is some inconsistency. But I don´t know if it is caused by the Facebook API or by the wrapper of the Rfacebook package.
      I definitely will have a look at it and will also ask the developer of the package.
      I´ll reach out to you as soon I have some more details.

      Regards

  • https://www.facebook.com/saulius.preidys Saulius Preidys

    Hi guys. I have problem/error when using command me <- getUsers("me", token=fb_oauth ): Error in callAPI(query, token) :
    An active access token must be used to query information about the current user.
    Where I can find solution of this problem?

    Full program code:

    require("Rfacebook")
    require("Rook")
    fb_oauth <-fbOAuth(app_id="235680489948000", app_secret="d3e67a6ad8dfba19fb9191d409de3123")
    save(fb_oauth, file="fb_oauth");
    load("fb_oauth");
    me <- getUsers("me", token=fb_oauth )
    my_friends <- getFriends(token=fb_oauth)

    • http://thinktostart.wordpress.com julianhi

      Hey Saulius,
      did you receive
      Authentication complete.
      Authentication successful.
      After calling the fb_oauth function?

      Regards

      • https://www.facebook.com/saulius.preidys Saulius Preidys

        Hello Julianhi,

        Thanks for trying to help me.
        There is all log file of my actions: https://copy.com/G4hT3J6f3y8kVn1K
        Any suggestion? Thanks.

        • http://thinktostart.wordpress.com julianhi

          Hey Saulius,
          there seems to be a problem with the authentication when you have to allow the access in the web browser. The R session should return
          Authentication complete.
          AND
          Authentication successful.

          The last one is missing.
          Please try to create a new Facebook app and connect to the new one. Seems like there are some settings cached.

          Regards

  • https://www.facebook.com/saulius.preidys Saulius Preidys

    Updated R from 3.0.0 to 3.0.3, but result are same (without warning)…

  • Munish

    Hi,

    I am facing problem with authentication. After it says to press key:

    I am having error:

    Error in authorizer(authorize_url) :
    httpuv package required to capture OAuth credentials.

    The settings are fine on app. I am using windows and fireforx 27.0.1

    • http://thinktostart.wordpress.com julianhi

      Hey Munish,
      please try:

      install.packages(“httpuv”)

      before you run the code.

      Regards

  • Munish

    Oh Thanks, It was written just there. I am new to R.

  • Munish

    After it says authentication completed. It throws error: Error: Deprecated: supply token object to config directly

  • Pingback: Facebook data collection and photo network visualization with Gephi and R()

  • https://www.facebook.com/naveen.srikanth Naveen Srikanth

    my_friends <- getFriends(fb_oauth,simplify=TRUE)
    Error in matrix(unlist(content$data), ncol = 2, byrow = TRUE) :
    'data' must be of a vector type, was 'NULL'. Please help me in resolving this issue

    • http://thinktostart.wordpress.com julianhi

      Hey Naveen,
      did you receive “Authentication successful” after the authentication process?

      Regards

  • whitestorm2k

    Hi Julian
    Thanks for sharing this article.
    I’m having a problem to call getUsers(“me”,token=fb_oauth). How to fix it?
    Thanks a lot!

    > fb_oauth save(fb_oauth, file=”fb_oauth”)
    > load(“fb_oauth”)
    > me <- getUsers("me",token=fb_oauth)
    Error in callAPI(query, token) :
    (#12) username is deprecated for versions v2.0 and higher

    • http://thinktostart.wordpress.com julianhi

      Hey,
      do you use the newest version of the Rfacebook package?
      Please check it with
      update.packages(“Rfacebook”)
      Does this work?

      Regards

  • Pingback: Analyzing Facebook Networks using #rstats « DECISION STATS()

  • whitestorm2k

    Hi,
    I use the newest version of the Rfacebook pkg and it doesn’t work.
    Would you please run your example without error, now?

    (https://developers.facebook.com/docs/apps/changelog, => /me/username is no longer available.)

  • tasos

    I got the same problem with function: > me <- getUsers("me", token=fb_oauth, private_info=FALSE)
    Error in callAPI(query, token) :
    (#12) username is deprecated for versions v2.0 and higher

    any idea???? thx in advance

  • https://www.facebook.com/naveen.srikanth Naveen Srikanth

    Hi Julinahi , yes I got the authentication message and one interesting thing I am getting this error only when I am using my own api . I have named the api as Naveen if I select GraphAPI I am not getting this error and when I try to extract the friends list I am getting the list of only 3 friends but I have the friends list of more than 400.

    • http://thinktostart.wordpress.com julianhi

      Hey Naveen,
      Facebook made a big change to it´s API what causes a lot of errors when you execute this code and makes it not usable anymore. As soon as I can find a solution I will update the code.
      Follow me on Twitter or add my Blog to stay up-to-date.

      Regards
      Julian

  • EQD

    hey, Same error :

    got the same problem with function: > me <- getUsers("me", token=fb_oauth, private_info=FALSE)
    Error in callAPI(query, token) :
    (#12) username is deprecated for versions v2.0 and higher

    • http://thinktostart.wordpress.com julianhi

      Hey EQD,
      Facebook made a big change to it´s API what causes a lot of errors when you execute this code and makes it not usable anymore. As soon as I can find a solution I will update the code.
      Follow me on Twitter or add my Blog to stay up-to-date.

      Regards
      Julian

  • Briti

    Hi .. many many thnx for the nice post:)
    How ever I am getting the following error while using the function
    > me <- getUsers("me", token=fb_oauth, private_info=FALSE)
    Error in callAPI(query, token) :
    (#12) username is deprecated for versions v2.0 and higher

    Can anyone suggest somethings on this

    • http://thinktostart.wordpress.com julianhi

      Hey Briti,
      Facebook made a big change to it´s API what causes a lot of errors when you execute this code and makes it not usable anymore. As soon as I can find a solution I will update the code.

      Regards
      Julian

  • Briti

    Hello Julianhi;

    I have find a alternative for that. Instead of me one has to use separate url now because facebook has changed the setting.
    path=”v1.0/me”
    access_toke=”….”
    url <- sprintf( "https://graph.facebook.com/%s?access_token=%s&quot;, path, access_toke)
    data <- getURL( url, ssl.verifypeer = FALSE)
    my_profile=fromJSON( data )

    This will work !!:)

    • http://thinktostart.wordpress.com julianhi

      Hey Briti,
      thanks for your suggestion. But it is not about directly connecting to Facebook or getting the data. It is more about the logical structure of the Facebook API which makes it hard. Facebook deprecated a lot of feature like the one you are using in your example. It is from version 1 but the Facebook API version is now 2. This works when you use the Graph API directly. But to make it easier the Rfacebook package uses the connection to a Facebook app. And all new created apps use the API version 2 now.
      But I think in a few days there will be an update to the Rfacebook package and I will update my post.

      Regards

  • Louise

    Hey Julian,

    Any news about the problem?

    • http://thinktostart.wordpress.com julianhi

      Hey Lousie,
      unfortunately there are no new news. But I will follow this topic and try to find a solution as soon as possible.

      Regards

  • Ning Chen

    Hi Julianhi,

    I am an beginner for R and Facebook API, and thanks for your article, which is very detail and helpful. It makes me have a progress on learning R and Facebook API.

    I am lost somewhere…
    When I do the action – fb_oauth <- fbOAuth(app_id="123456789", app_secret="1A2B3C4D"), it connect to the browser and shows the error message-
    "Given URL is not allowed by the Application configuration.: One or more of the given URLs is not allowed by the App's settings. It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App's domains."

    I try to get answer from internet, but failed. Could you give me some clues?

    Thanks a lot,

    Ning

    • http://thinktostart.wordpress.com julianhi

      Hey,
      I´m sorry but Facebook made a big change to the API and so the tutorial does not work at the moment. I´m trying to find a solution at the moment.
      Please follow me on Twitter to stay up-to-date.

      Regards

    • Djamila

      Hello
      You have to paste url (http://localhost:1410/ ) in developer app settings

      1- Click on add platform.
      2- Choose website and paste http://localhost:1410/ in URL link.

      • Tuang

        I got it to work as Djmilla suggested steps.
        But when I try to access my friends from this token it return 0 friends.
        Is it because it’s a dummy app. with no friends?
        -t

        • http://thinktostart.com/members/julianhi/ Julian Hillebrand

          Hey
          so the app does not have to have any users. It is just the connection we use to connect R with your
          personal Facebook account. So if you did the authentication with your personal Facebook credentials in the browser
          you should be able to get all the data of your friends.
          But: You have to give the app the right permissions. So also the rights to access your friends data.
          And your friends also have the possibility to change their privacy settings so that you are not able anymore to
          access their data. And this is the most common reason why no friends data is returned.

          Regards

  • Pushkar

    Hey Julianhi,

    Very nice tutorial. Helped me a lot!! :)
    I am using Rfaceook package to retrieve the data from a facebook page. I am using temporary token (valid for 2 hrs to do so).
    I am getting the posts which are published by the page owner. Is it any way to retrieve the posts of people who actually posted something on the page?

    Thanks,
    Pushkar

    • http://thinktostart.com/members/julianhi/ Julian Hillebrand

      Hey
      I think there is a way. But you don´t have a direct function for this. So you would need a combination of different functions.
      But I will post some tutorials about the Rfacebook package in the next months. Maybe I will also write one about the problem you mentioned.

      regards

  • Mateusz1981

    Hej
    I am little bit lost. Have you upgraded your tutorial?
    I succesfuly made fboAuth but with my app_id and app_secret but receive an error now

    Error in callAPI(query, token) :
    (#12) username is deprecated for versions v2.0 and higher

    when I want to use

    me_d <- getUsers(user="me", token=fb_oauth )

    • http://thinktostart.com/members/julianhi/ Julian Hillebrand

      Hey,
      yes I updated the tutorial because of a change in the Facebook API.
      In the former version I used the authentication through a Facebook app.
      But this does not work anymore so I changed it to a version where you use a temporary auth token.
      This should work. When exactly does your error happen?

      Regards

      • Vivek Agarwal

        I am still getting same error while using temporary token.

        me <- getUsers("me", token=token)

        Error in callAPI(query, token) :
        (#12) username is deprecated for versions v2.0 and higher

        Please let me know how to resolve this issue?

        regards,
        Vivek Agarwal

        • http://thinktostart.com/members/julianhi/ Julian Hillebrand

          Hey
          there will be an update on the Facebook post as there were some changes on the Rfacebook package.
          I will update it in a few days.

          Regards

  • Djamila

    Hi
    I tried the command
    me <- getUsers("me", token=fb_oauth) . but it gives: Error in callAPI(query, token) : (#12) username is deprecated for versions v2.0 and higher

    and when i changed "me" by my username i have this error:
    Error in callAPI(query, token) : (#803) Cannot query users by their username (Djamila)

    So what's the problem?

    Regards

    • Djamila

      Note: i didn’t use a tomporary access tocken but i created OAuth tocken (with creating an app)

      • http://thinktostart.com/members/julianhi/ Julian Hillebrand

        Hey
        there is a problem when you use the way with a OAuth token by creating an app.
        If you create a app this automatically uses Facebook API V2 and this version is not compatible with the
        current version of the Rfacebook package.
        So at the moment you have to use the way with the temporary auth token.

        As soon there is a new version of the Rfacebook package I will update my tutorial.

        Regards

  • Pingback: Gender Analysis of Facebook Post Likes - ThinkToStart()

  • sibusiso

    Hey Julianhi,

    When I run the ff. code, I only get info for 1 friend, and there should be more that that.

    d> my_friends getUsers(my_friends$id, token, private_info = TRUE)

    Rgds,
    Sibusiso

    • http://thinktostart.com/members/julianhi/ Julian Hillebrand

      Hey,
      this is probably because the rest of your friends have high privacy settings.
      They don´t seem to allow these kind of requests to their profile.
      I heard of this problem from several people, but I don´t know a way to get the information even
      when the privacy settings forbid it.

      Regards

    • stefa

      I also find two of my friends there, same appears when i use the graph API explorer.
      both of them are probably developer.
      i’m quite sure that many of my friends don’t have high privacy settings
      Do you know a solution for that problem?

      • http://thinktostart.com/members/julianhi/ Julian Hillebrand

        Hey
        I don´t know a solution yet.
        And I can´t think of a way how you could get this information as they seem to be blocked by Facebook.
        If I know something new I will update the tutorial.

        Regards

  • stefan

    https://developers.facebook.com/docs/facebook-login/permissions/v2.0#reference-user_friends
    seems like facebook only allows apps to access friends which are also using the app

  • http://rhandbook.wordpress.com/ Ajay

    I am trying to generate my facebook friend list using Rfacebook but after api ver 2.2, it generate the list of friends who are using the same app. I tried the same with “unversioned” but with no help.

    getFriends function of Rfacebook lost its meaning after ver 2.2 as it return subset of friends, depends whether your friend using same app. Please help, if Pablo can do some tweak in his library.

    • http://thinktostart.com/members/julianhi/ Julian Hillebrand

      Hey
      there will be an update on the Facebook post as there were some changes on the Rfacebook package.
      I will update it in a few days.

      Regards

  • Rajeev

    Hey Julian,

    Thanks for wonderful tutorial. However I am not been able to use it as I am getting usual error (reported by many already)

    Error in callAPI(query, token) :
    (#12) username is deprecated for versions v2.0 and higher

    Just to note that I am using temporary access token (lifetime of 2 Hrs). I though such problem is happening only for OAuth token using App.

    Cheers,
    Rajeev

    • http://thinktostart.com/members/julianhi/ Julian Hillebrand

      Hey
      there will be an update on the Facebook post as there were some changes on the Rfacebook package.
      I will update it in a few days.

      Regards

  • spykeburn

    I followed all the steps. But I can see only one friend information. And in the end I get “character(0)” What does it mean?

  • spykeburn

    Can anyone please tell me why am I able to see only one friend’s information ?? Why not all?

    • Sahil Raj

      Because in Graph API 2.0 onward the ability to harvest the public data has been deprecated. Still you can collect data for any facebook page.

  • spykeburn

    OK I got the problem. When I selected “Select permissions” I got only two types- user data permissions and extended permissions. Please tell me how do I get the friends permissions option?

  • rajani

    Error in callAPI(query, token) :
    (#12) username is deprecated for versions v2.0 and higher

    please solve this problem .earlier it was working fine but from today it is giving this error please solve this problem …

    • http://thinktostart.com/members/julianhi/ Julian Hillebrand

      Hey
      there will be an update on the Facebook post as there were some changes on the Rfacebook package.
      I will update it in a few days.

      Regards

  • Siddharth

    Hi Julian,

    Could you please tell me if there is an update on the Rfacebook package ? Because I am still facing the authentication problem (“Given URL is not allowed by the Application configuration.: One or more of the given URLs is not allowed by the App’s settings. It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App’s domains.”). Thanks for the help .

    • http://thinktostart.com/members/julianhi/ Julian Hillebrand

      Hey
      where exactly does this problem appear?
      In the R console?

      Regards

  • Barry Higgins

    Great tutorial, really well laid out, well done. Just one issue I got the following warning message after I get confirmation from my browser

    Authentication complete.
    Authentication successful.
    Warning message:
    In class(fb_oauth)[4] me <- getUsers("me",token=fb_oauth)
    Error in token$sign : object of type 'S4' is not subsettable

    Any ideas on what could be causing this issue?

    Thanks

    Barry H

    • http://thinktostart.com/members/julianhi/ Julian Hillebrand

      Hey
      I don´t exactly know where this warning comes from. This seems to be a problem with the Rfacebook package. Did you update it to the last version?
      Otherwise did you notice that something is not working because of this warning?

      Regards

      • Alejandro

        Hi Julian,

        I am getting the same error than Barry. When I create fb_oauth I get displayed this message:

        Copy and paste into Site URL on Facebook App Settings: http://localhost:1410/
        When done, press any key to continue…
        Waiting for authentication in browser…
        Press Esc/Ctrl + C to abort
        Authentication complete.
        Authentication successful.
        Warning message:
        In class(fb_oauth)[4] me <- getUsers("me", token=fb_oauth)
        Error in token$sign : object of type 'S4' is not subsettable

        I assume this error is coming from the warning message above.

        Thanks,

        Alejandro

        • http://thinktostart.com/members/julianhi/ Julian Hillebrand

          Seems like there is something wrong with the package at the moment as I heard the same error from some users now.
          I will take a look at it.

          Regards

      • Sam

        I receive the same error.

        When I initially authenticate and the browser loads Facebook I get this error

        “Invalid Scopes: friends_birthday, friends_hometown, friends_location, friends_relationships, user_checkins, friends_status, friends_checkins, friends_likes, export_stream. This message is only shown to developers. Users of your app will ignore these permissions if present. Please read the documentation for valid permissions at: https://developers.facebook.com/docs/facebook-login/permissions

        I can then continue fine until I try and pull results at which point i receive the error below. I’m using the getPage function..
        Error in token$sign : object of type ‘S4′ is not subsettable

        Any ideas?

        • http://thinktostart.com/members/julianhi/ Julian Hillebrand

          Hey

          seems like you choose the wrong permissions when you create your access token.
          This seems to be a bug in the package. Could you please open an issue for your problem at github? (https://github.com/pablobarbera/Rfacebook/issues)
          I think Pablo will be able to help you.

          Regards

  • Belinda

    Worked !! Thank you

    • http://thinktostart.com/members/andrade-rdz/ Ricardo D.

      Belinda, can you tell me what method worked for you? and what info did you reached? I’m new at this and I really want to learn. I’m trying to do a task in my job.

  • kangkan

    Hi,

    Thanks for the detailed blog

    I ran fb_oauth <- fbOAuth(app_id="XXXXX", app_secrete="XXXXXX",extended_permissions = TRUE) and waited for a few minutes. But after the pop up for authentification started, the browser returned the web page is not available and R simultaneously crashed. This has happaned repeatedly . I have tried switching default browers, but i am getting the same crash. Would be grateful if any body can help.

    Regards

    • http://thinktostart.com/members/julianhi/ Julian Hillebrand

      Hey
      do you use RStudio? If so you could try it with the R console as there sometimes appear problems during the authentication process with RStudio.

      Regards

      • kangkan

        Hi Julian,

        I was working from the R console only.

        The error message i am getting from the browser is localhost:1410 not found.

        Thanks

  • Pingback: Rfacebook and video retention graphs | weatherlisa()

  • omid

    I got the same problem as : kangkan

  • jeff

    Hi,
    I have some problems.
    when I run below coding;

    my_friends

    How can solve this problem Sir?

    Best,

    Jeff

    • http://thinktostart.com/members/julianhi/ Julian Hillebrand

      Hey
      could you please post the code you are using?

      Regards

  • http://thinktostart.com/members/sandy/ sanchit shaleen

    Hi,
    I am facing an error when I execute the command “me <- getUsers("me",token=fb_oauth)" and the error says :
    "Error in token$sign : object of type 'S4' is not subsettable"

    Please help to resolve
    Thanks

  • Avneet

    Hi Julian,
    Can you tell the error in the following code?

    page page <- getPage("CNN", n=1000, token=fb.oauth,
    + since = '2015/02/01',
    + until = '2015/02/28')

    Error in callAPI(url = url, token = token) : An unknown error occurred

    • http://thinktostart.com/members/julianhi/ Julian Hillebrand

      No as it as an unknown error 😀
      But did you try to execute it all in one line? It might sound strange but seems it helps.
      Otherwise you should open up an issue on the package github page: https://github.com/pablobarbera/Rfacebook/issues

      Regards

  • Binayak

    Nice page Julian ! Thank you !
    Does it have the functionality to get data from many users? I’m interested in Sentiment Analytics.

    • http://thinktostart.com/members/julianhi/ Julian Hillebrand

      Since the version 2 the possibilities are very limited. I don´t think that it is possible at the moment.

      Regards

  • byambadorj

    Hi, I’m newbie. I want to get my ego-network of my facebook friends ? what should i do?

    • byambadorj

      Only friends who use the application will be returned???
      See ?getFriends for more details
      Error in getFriends(token = fb_oauth, simplify = F) :
      No friend information is available.

      How can i get others information???

      • byambadorj

        Sorry my bad. Didn’t see posts about it

        • http://thinktostart.com/members/julianhi/ Julian Hillebrand

          Ok so now everything works for you?

  • Nishant

    Hey JUlian,

    After reading above post i got my answer, Extended_permission=False worked for me .

    Thanks

  • Manu Sharma

    Hi Julian,

    Thanks for this important post, but I am getting thie error on Rstudio and R console both
    me <- getUsers("me",token=fb_oauth)

    Error in callAPI(query, token) :
    An active access token must be used to query information about the current user.

    Pls help! Thanks -Manu

    • http://thinktostart.com/members/julianhi/ Julian Hillebrand

      Hey there are several people with this problem.
      I will take a look at the authentication problems.

      Regards

      • jklatt

        Hi Jullian,
        Any Update on the authentication problems?
        thanks

  • Tanmay

    Brilliant article Julian. But unfortunately I’m not yet able to get it work. Here are the observations:

    1. During authentication I get following error on the Facebook page:
    “Invalid Scopes: friends_birthday, friends_hometown, friends_location, friends_relationships, user_checkins, friends_status, friends_checkins, friends_likes, read_stream, export_stream. This message is only shown to developers. Users of your app will ignore these permissions if present. Please read the documentation for valid permissions at: https://developers.facebook.com/docs/facebook-login/permissions
    2. And when I click ‘Okay’ it gives the following message: “Authentication complete — you can now close this page and return to R”.
    3. I get ‘Authentication Completed’ message but never get ‘Authentication Successful’ message on R console.
    4. After that when I tried running the following command:
    me <- getUsers("me", token=fb_oauth)
    It gave an error:
    Error in callAPI(query, token) :
    An active access token must be used to query information about the current user.

    I read through all the posts but unfortunately none of the folks face the error I faced in item#2 above. Would be grateful to see your reply. Thanks.

    • http://thinktostart.com/members/julianhi/ Julian Hillebrand

      Hey
      thank you Tanmay.
      Did you check if you have set the permissions right when you created the access token?
      Or did you try to authenticate via an app?

      Regards

      • AC

        Hi Julian and Tanmay,

        I have the same error.

        When I switched extended_permissions to false, I get the authentication successful message. Of course, that means I’m no longer privy to all the information so it’s not exactly a viable solution.

        How would I authenticate via the app?

        Thanks!

        AC

      • Aakash Gupta

        Hi Julian, any updates on the above permission problems?

        fb_oauth <- fbOAuth(app_id="________", app_secret="xxxxxx",extended_permissions = FALSE)
        me >>
        Error in callAPI(query, token) :
        An active access token must be used to query information about the current user.

        So I generated a token from the Graph Explorer API and then used it with the getUsers function
        However this approach doesn’t work with the getPosts function
        If any one has been able to get get authentication through the app, could you share it.

  • shan

    Hi.. Julian…
    Your tutorial is useful..
    I am getting this error at console :
    Error: unexpected numeric constant in “fb_oauth1 <- fbOAuth(app_id="——-",app_secret="——
    Pls guide.
    Thanks

    • http://thinktostart.com/members/julianhi/ Julian Hillebrand

      Hm could you please show me the exact code you used?

      Regards

  • shan
  • Sam

    Hello all,
    So, what are some of the functions that don’t work anymore? I used ‘unversioned’ instead of v2.4. My authentication didn’t return ‘successful’ while using latter. Are some functions compatible with certain versions?

    Also, I am only retrieving information about four of my friends? How can i get extended permissions? I am just wanting to get data for personal use. ( just playing with Rfacebook and fb-API)

    • http://thinktostart.com/members/julianhi/ Julian Hillebrand

      Hey Sam
      Pablo updated the package and all the functions now work with the new API version: https://github.com/pablobarbera/Rfacebook

      But the new API version caused some strange behaviour when you want to get results about your friends. There is no way
      to get information about all your friends at the moment.

      Hope I could help you

      Regards

  • Clara Z

    Copy and paste into Site URL on Facebook App Settings: http://localhost:1410
    When done, press any key to continue…
    Error: Deprecated: supply token object to config directly
    How can I solve it?

  • aliamala

    Hi , When I use fbOAuth function
    It shows Authentication complete.
    But I didn’t saw Authentication successful.
    I get this message Error: Deprecated: supply token object to config directly
    Can you help me?

  • Poopp

    Hi, could you please guide me in getting the comments for the posts? Thank you.

    • Julian Hillebrand

      Hey
      so you want to also get the comments of a post?
      Then setting comments to TRUE should work for you.

      post <- getPost(post_id, token, n = 1000, likes = TRUE, comments = TRUE)

      Best regards
      Julian

      • Poopp

        Is it possible to get comments from multiple posts? Thank you.

  • Poopp

    Hi, after running the line getPage, i have this error: failed to connect to localhost port 4444 connection refused
    May I know how to solve it? Thanks.