First, we load dplyr
and lubridate
to use in this vignette along with loading the rdfp
package and specifying the DFP network we would like to connect to.
suppressWarnings(suppressMessages(library(dplyr)))
suppressWarnings(suppressMessages(library(lubridate)))
library(rdfp)
options(stringsAsFactors = FALSE)
options(rdfp.network_code = 123456789)
Just a note, that it’s not necessary to setup your own application client_id and client_secret through the Google Developer’s Console. The only difference is that the authentication will be run through the client created and associated with the rdfp
package. By using the package client, you will NOT be giving access to your DFP to anyone, the package is just the medium for you to connect to your own data. If you wanted more control you would specify those options like so:
options(rdfp.application_name = "MyApp")
options(rdfp.client_id = "012345678901-99thisisatest99.apps.googleusercontent.com")
options(rdfp.client_secret = "Th1s1sMyC1ientS3cr3t")
dfp_auth()
# Check current user or network
user_info <- dfp_getCurrentUser()
user_info[,c('id', 'isActive')]
#> # A tibble: 1 x 2
#> id isActive
#> <dbl> <chr>
#> 1 185549536. true
network_info <- dfp_getCurrentNetwork()
network_info[,c('id', 'networkCode')]
#> # A tibble: 1 x 2
#> id networkCode
#> <dbl> <dbl>
#> 1 109096. 1019096.
# create a team and user and add the user to that team
#first create the team
request_data <- list(teams=list(name="TestTeam1",
description='API Test Team 1',
hasAllCompanies='true',
hasAllInventory='true',
teamAccessType='READ_WRITE'))
dfp_createTeams_result <- dfp_createTeams(request_data)
# second create the user
request_data <- data.frame(name = paste0("TestUser", 1:3),
email = paste0('testuser', 1:3, '@gmail.com'),
roleId = rep(-1, 3))
dfp_createUsers_result <- dfp_createUsers(request_data)
# third associate the user to that team
request_data <- data.frame(teamid=rep(dfp_createTeams_result$id, 3),
userid=dfp_createUsers_result$id)
dfp_createUserTeamAssociations_result <- dfp_createUserTeamAssociations(request_data)
# Note: User roleId = -1 is the Administrative role
# use dfp_getAllRoles() to view other options
# Creating custom roles is a premium feature, which
# small business accounts won't have and creating the roles
# can only be done from the user interface, not the API.
# create a company and add a contact to it
# first create the company
request_data <- list(companies=list(name="TestCompany1",
type='HOUSE_ADVERTISER',
address='123 Main St Hometown, FL USA',
email='testcompany1@gmail.com',
comment='API Test'))
dfp_createCompanies_result <- dfp_createCompanies(request_data)
# second create the contact and specify the companyId
request_data <- list(contacts=list(name="TestContact1",
companyId=dfp_createCompanies_result$id,
status='UNINVITED',
cellPhone='(888) 999-7777',
comment='API Test',
email='testcontact1@gmail.com'))
dfp_createContacts_result <- dfp_createContacts(request_data)