R/fb_image.R

Defines functions fbad_create_image

Documented in fbad_create_image

#' Upload image
#' @inheritParams fbad_request
#' @param img file path
#' @return list of file name, hash and URL
#' @export
#' @references \url{https://developers.facebook.com/docs/marketing-api/reference/ad-image#Creating}
fbad_create_image <- function(fbacc, img) {

    fbacc <- fbad_check_fbacc()

    ## we need an img file
    if (missing(img) || !file.exists(img)) {
        stop('A valid image file path is required.')
    }

    ## get results
    res <- fbad_request(fbacc,
        path   = paste0('act_', fbacc$account_id, '/adimages'),
        method = "POST",
        params = list(image_file = fileUpload(img)))

    ## parse JSON
    res <- fromJSONish(res)[[1]]

    ## return
    list(filename = names(res), hash = res[[1]]$hash, url = res[[1]]$url)

}
cardcorp/fbRads documentation built on March 27, 2024, 12:43 a.m.