fbRads v0.2


Monthly downloads



Analyzing and Managing Facebook Ads from R

Wrapper functions around the Facebook Marketing 'API' to create, read, update and delete custom audiences, images, campaigns, ad sets, ads and related content.



This R package includes wrapper functions around the Facebook Marketing API to create, read, update and delete custom audiences, images, campaigns, adsets, ads and related content.

Vignette and more detailed documentation is coming soon, until then please see the slides presented at useR! 2015, EARL 2015, the Los Angeles R Users Group and at a Domino Webinar.

Creating a Facebook App & connect with OAuth token

To be able to use this package, you will have to create a Facebook App and authorize it to mange your Facebook ads. Basic steps to create an app with Development access level letting you manage up to 5 Facebook ad accounts:

  1. Create new application at https://developers.facebook.com/apps with "basic setup".
  2. Fill in a unique Display Name (eg "app_testing_foobar_42"), set the category to eg "Business". Click on "Create App ID" & pass the captcha test.
  3. In "Settings/Basic", click "Add Platform" add create "Website" platform with the URL of http://localhost:1410/ and "localhost" as the "App Domain". Click "Save Changes".
  4. In the "Settings/Advanced" tab, add http://localhost:1410/ as the "Valid OAuth redirect URIs". Click "Save Changes".
  5. Note your "App ID" and "App Secret" on your dashboard, and use those in the below R script to get a token for future authentication:

     app <- oauth_app('facebook', 'your app id', 'your app secret')
     Sys.setenv('HTTR_SERVER_PORT' = '1410/')
     tkn <- oauth2.0_token(
         oauth_endpoints('facebook'), app, scope = 'ads_management',
         type  = 'application/x-www-form-urlencoded', cache = FALSE)
     tkn <- tkn$credentials$access_token
  6. Please note the above last step: we store the token as a string. Now you can save that token in a safe place and start using fbRads, eg:

     fbad_init(accountid = accountid, token = tkn, version = '2.5')
  7. And list all your ads along with the ad name and status or eg filter for the active ads:

     fbad_list_ad(fields = c('name', 'effective_status'))
     fbad_list_ad(statuses = 'ACTIVE', fields = 'name')

Using the package

This package makes your life more convenient when it comes to interacting with the Facebook Marketing API, but unfortunately, it cannot save you the time to get familiar with the actual API. To be able to interact with Facebook, you have to learn about how the API works etc -- see the documentation at https://developers.facebook.com/docs/marketing-apis

This package was developed and being maintained at CARD.com, licensed under AGPL-3.

Functions in fbRads

Name Description
fbad_request Get results of a synchronous query from FB graph API
fbad_delete_audience Delete a FB custom audience
fbad_create_creative Create an ad creative
fbad_insights_get_async_results Wait for and get asynchronous report results
fbad_list_ad List all Ads for current account, list of Ad Sets or Campaigns
fb_insights Insights
fbad_list_adset List all Ad Sets for current account or Ad Campaign(s)
fbad_update_adset Update Ad Set
fbRads fbRads package
fbad_check_curl_params Run basic checks on curl get/post parameters
fbad_add_audience Add people to a custom FB audience
fbad_create_lookalike_audience Create a new FB lookalike audience similar to an already existing custom audience
fbad_create_campaign Created Ad Campaign
fbad_create_audience Create a new FB custom audience
this_function_name Return the name of the parent function
fbad_create_image Upload image
fbad_list_campaign List all Ad Campaigns for current account
fb_reportstats_ad Get Ad Report Stats
fbad_share_audience Share a FB custom audience with other accounts
fbad_read_campaign Read Ad Campaign details
fb_stats_ad Get Ad Stats
fb_api_version Returns the currently used version of the Facebook Marketing API
fbad_read_audience Read metadata on a FB custom audience
fbad_update_ad Update ad
fbad_create_adset Create Ad Set
fbad_update_campaign Update Ad Campaign
fbad_check_fbacc Check if provided or previously initialized R object is a valid FB Ad Account
fb_api_most_recent_version Returns the most recent version of the supported Facebook Marketing API
fbad_create_ad Create ad
fbad_remove_audience Add people from a custom FB audience
fbad_read_ad Read ad details
fbad_get_adaccount_details Get details for a Facebook Ads Account
fbad_get_search FB Search API Querying
fbad_read_adset Read Ad Set details
print.FB_Ad_Account Print method for custom fbRads class
fbad_init Initiate Facebook Account with OAuth token
fbad_reachestimate Query for reach estimate for given targeting spec
fbad_read_creative Read ad creative
No Results!

Last month downloads


Type Package
Date 2016-04-04
URL https://github.com/cardcorp/fbRads
License AGPL-3
NeedsCompilation no
Packaged 2016-04-05 19:57:35 UTC; daroczig
Repository CRAN
Date/Publication 2016-04-06 01:20:49

Include our badge in your README