NOT_CRAN <- identical(tolower(Sys.getenv("NOT_CRAN")), "true") knitr::opts_chunk$set( collapse = TRUE, comment = "#>", purl = NOT_CRAN, eval = NOT_CRAN )
First, we load rdfp and specify the DFP network we would like to connect to.
Then we authenticate by using dfp_auth()
. Any existing cached token would be used
or we will be prompted to authenticate via the browser.
library(rdfp) options(rdfp.network_code = 123456789) dfp_auth()
library(here) library(rdfp) token_path <- here::here("tests", "testthat", "rdfp_token.rds") suppressMessages(dfp_auth(token = token_path, verbose = FALSE)) options_path <- here::here("tests", "testthat", "rdfp_options.rds") rdfp_options <- readRDS(options_path) options(rdfp.network_code = rdfp_options$network_code)
This example uses a test company as an advertiser and yourself as the trafficker, to create an order.
request_data <- list('filterStatement'=list('query'="WHERE name = 'TestCompany1'")) dfp_getCompaniesByStatement_result <- dfp_getCompaniesByStatement(request_data) request_data <- list(list(name='TestOrder', startDateTime=list(date=list(year=2018, month=12, day=1), hour=0, minute=0, second=0, timeZoneID='America/New_York'), endDateTime=list(date=list(year=2018, month=12, day=31), hour=23, minute=59, second=59, timeZoneID='America/New_York'), notes='API Test Order', externalOrderId=99999, advertiserId=dfp_getCompaniesByStatement_result$id, traffickerId=dfp_getCurrentUser()$id)) dfp_createOrders_result <- dfp_createOrders(request_data)
Below is an example of how to get objects by Publishers Query Language (PQL) statement.
The statement is constructed as a list of lists that are nested to emulate
the hierarchy of the XML to be created. The example uses the dfp_getLineItemsByStatement
function from the [LineItemService] (https://developers.google.com/ad-manager/api/reference/v201905/LineItemService)
# retrieve 3 line items that have a status of "DELIVERING" request <- list('filterStatement'=list('query'="WHERE status='DELIVERING' LIMIT 3")) resultset <- dfp_getLineItemsByStatement(request, as_df=TRUE) resultset[,c('orderId', 'id', 'priority', 'deliveryRateType')]
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.