All About Using Python & R for Machine Learning, Data Science, Data Analyst, Deep Learning, Artificial Intelligence

Friday, November 10, 2017

How to connect Facebook with R

Data analysis is one of subjects that very popular in last decade. Most of them start to think about big data analytics in business, education, and also government area. However, this post will do data analytics using R from social media such as facebook. The question is How we can connect to facebook. And here, I will give an example.

1. Facebook Developer Registration

To access data from facebook, we should be a developer. This is the first step to implement data analysis from facebook. Go to https://developers.facebook.com/products/account-creation and register yourself by clicking on Get Started button at the top right of page. After it would open a form for registration which you need to fill it to get yourself registered as facebook account.
login ataberuntung

2. Get App ID

After step one, we need to note down our App ID and App Secret (Refers to the screen-shot below)
App ID ataberuntung

3. Setting of OAuth

On the left side menu, click on "+Add Product" Button
Click on Facebook Login link
Under Settings, make sure YES is selected in Client OAuth Login
Type http://localhost:1410/ in Valid OAuth redirect URIs box
Click on Save Changes button
Authentication ataberuntung


please noted, If you didn't write information correctly, you would get the following error:
Can't Load URL: The domain of this URL isn't included in the app's domains. To be able to load this URL, add all domains and subdomains of your app to the App Domains field in your app settings.

4. Test Connection with R Script

a. Install required packages

Go to R and install Rfacebook and RCurl packages. Run the following code to install them.
  The package Rfacebook lets you to access Facebook App via R.

b. Load desired packages

In this step, we will load the above installed packages.


c. Write function to handle Authentication


d. Paste your app id and app secret below

Press ENTER in R Console or CTRL+ENTER in R Studio.

It would return the following message :
And if connection is successful, will get notify:
Successful connect ataberuntung

Test to update status on Facebook via R

Next step is data collection

Share:

0 comments:

Post a Comment

Pageviews

Visitors

Flag Counter