2

As this announcement mentions (https://www.facebook.com/business/news/transparency-social-issue-electoral-political-ads) new targeting information (or a summary) has been made available in the Facebook Ad Library.

I am used to use the 'Radlibrary' package in R, but I can't seem to find any fields in 'Radlibrary' which allows me to get this information? Does anyone know either how to access this information from the Radlibrary package in R (preferred, since this is what I know and usually works with) or how to access this from the API in another way?

I use it to look at how politicians choose to target their ads, why it would be a too big of a task to manually look it up at the facebook.com/ads/library

EDIT The targeting I refer to is found browsering the ad library like the screenshots below

enter image description here

enter image description here

1 Answers1

0

Thanks for highlighting this data being published which I did not know had been announced. I just registered for an API token to play around with it.

It seems to me that looking for ads from a particular politician or organisation is a question of downloading large amounts of data and then manipulating it in R. For example, to recreate the curl query on the API docs page:

curl -G \
-d "search_terms='california'" \
-d "ad_type=POLITICAL_AND_ISSUE_ADS" \
-d "ad_reached_countries=['US']" \
-d "access_token=<ACCESS_TOKEN>" \
"https://graph.facebook.com/<API_VERSION>/ads_archive"

We can simply do:

# enter token interactively so it doesn't get added to R history
token <- readline() 

query <- adlib_build_query(
    search_terms = "california",
    ad_reached_countries = 'US', 
    ad_type = "POLITICAL_AND_ISSUE_ADS"
)

response <- adlib_get(params = query, token = token)

results_df <- Radlibrary::as_tibble(response, censor_access_token = TRUE)

This seems to return what one would expect:

names(results_df)
#  [1] "id"                            "ad_creation_time"              "ad_creative_bodies"            "ad_creative_link_captions"     "ad_creative_link_titles"       "ad_delivery_start_time"
#  [7] "ad_snapshot_url"               "bylines"                       "currency"                      "languages"                     "page_id"                       "page_name"
# [13] "publisher_platforms"           "estimated_audience_size_lower" "estimated_audience_size_upper" "impressions_lower"             "impressions_upper"             "spend_lower"
# [19] "spend_upper"                   "ad_creative_link_descriptions" "ad_delivery_stop_time"

library(dplyr)
results_df |>
    group_by(page_name) |>
    summarise(n = n()) |>
    arrange(desc(n))

# # A tibble: 237 x 2
#    page_name                    n
#    <chr>                    <int>
#  1 Senator Brian Dahle        169
#  2 Katie Porter               122
#  3 PragerU                     63
#  4 Results for California      28
#  5 Big News Buzz               20
#  6 California Water Service    20
#  7 Cancer Care is Different    17
#  8 Robert Reich                14
#  9 Yes On 28                   14
# 10 Protect Tribal Gaming       13
# # ... with 227 more rows

Now - assuming that you are interested specifically in the ads by Senator Brian Dahle, it does not appear that you can send a query for all ads he has placed (i.e. using the page_name parameter in the query). But you can request for all political ads in their area (setting the limit parameter to a high number) with a particular search_term or search_page_id, and then filter the data to the relevant person.

SamR
  • 8,826
  • 3
  • 11
  • 33
  • What I'm interested in is getting the information on more specific targeting such as if the ad has been targetet people interested in "organic food" or "public transportation" as the announcement from Meta mentions (and which can be found when just browsing the ad library on facebook.com/ads/library). I can't see any fields in the Radlibrary package which allows me to get this information. – Mads F. Hove Aug 11 '22 at 10:15
  • @MadsF.Hove can you give an example of where the API has this capability? I don't think what you're describing is to do with the R package. Can you see any fields in the API that allow you to request this? As far as I can see everything in the Facebook API is in the R package. The API itself seems somewhat limited. – SamR Aug 11 '22 at 13:55
  • @MadsF.Hove also can you edit the question to post a screenshot or link to where this info is shown if you search in the browser? I can see the demographics of the viewers but not who the ads were targeted at - if I knew the specific place you were referring to it would help – SamR Aug 11 '22 at 14:28
  • I don't know how to check if the API has this capability unfortunately. I have added screenshots to the question from when I search on the browser. It is found under the "audience" tab – Mads F. Hove Aug 11 '22 at 20:05
  • The API parameters are at the bottom of [this](https://www.facebook.com/ads/library/api/?source=nav-header) page. It allows you to search for ads - but not for advertisers (you can search by `page_id` but you still need a keyword and also it only returns ads). The demographics information you are looking for is linked to the advertiser, not the ad, so it doesn't look like you can get it through the API. – SamR Aug 12 '22 at 07:34