Monday, 29 September 2014

Sentiment Analysis on Facebook data using R

Sentiment Analysis on Facebook Data Using R



  • Click on the below link and login with your facebook account

               https://developers.facebook.com 

  • Now go to APPs tab and click the option to create a new App
  • Window will be appear like this






  • Click on website options
  • Now give any name you want to give to your App
  • Then click on Create new facebook App Id
  • Choose category for your App(category-Apps for Pages)
  • After that click confirm to continue 
  • Window will be appear like this




  • Then click on Skip QuickStart
  • Your App will be Created and window will be look like this







  • Now go to setting and click on Add platform 






  • Select the website option and after we to have enter site Url like this

              http://localhost:1410/

  • After that save changes






  • Now open R Studio and install these packages Rfacebook,Rook,httpuv

                  install.packages(“Rfacebook”)
                  install.packages(“Rook”)
                  install.packages(“httpuv”)

  • then Run these libraries 

                  library(Rfacebook)
                  library(Rook)
                  library(httpuv)

  • Now run this code in R

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

  • You have to fill app_id and app_secret for this go previous facebook developers page
  • Click on show button to get the app_secret 
  • It will need your facebook Id password
  • Enter the facebook Id password in the pop-up window and submit it
  • Now you can see your app_secret
  • now copy the app-id and app_secret and paste in the double commas of the code

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

  • After running this function R studio show the message like this



                Copy and paste into Site URL on Facebook App Settings: http://localhost:1410/ 
                When done, press any key to continue...



  • We have already given the Site url,now press Enter, R studio show message like this


                Waiting for authentication in browser...
                 Press Esc/Ctrl + C to abort


  • For authentication one page will open in your default browser showing that your  authentication is done like this





  • R will show that authentication complete
  • Now we have create a token to access the facebook data for this go to https://developers.facebook.com facebook developers page and go to Tools on the page and Select Graph Api Explorer

  • Select the Api version as unversioned like this




  • Now select Get Access Token in pop-up window will be appear like this



  • Now select the all option and click on Get Access token
  • Another window will be open which will need your permission for accessing user facebook data, press okay for continue
  • Your Access Token will be generate in the box


  • Now go to R and type this

            token < - '  '

  • Write the Access token in the single commas and execute the function
  • Now for saving the authentication, write load("fb_oauth") in R
  • This will save your authentication
  • For getting username run the this code


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

  • It will return the username of the user
  • Now you can apply various Rfacebook package function like 


            my_newsfeed <- getNewsfeed(token=fb_oauth, n=100)
            my_newsfeed
            my_likes <- getLikes(user="me", token=token)
            my_likes

  • The above code will show your likes and recently 100 newsfeed


7 comments:

  1. Thank you for providing solution for problem that i couldn't find anywhere:)

    ReplyDelete
  2. how to dowanload the educational or study data set from facebook

    ReplyDelete
  3. you can go with function searchFacebook(string, token, n = 200, since = NULL, until = NULL) as well as with searchPages(string, token, n = 200) where you can put your required keyword as string="education" but remember for this functions to use you should have RFacebook package in your R tool

    ReplyDelete
  4. ese he kama kr tum loga popular hotaa....

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. but still cant searchFacebook(term,n) the way you do with twitter
    searchTwitter(term, n) is there another way to search facebook posts using r studio

    ReplyDelete
  7. version option is not showing in facebook developer

    ReplyDelete