Skip to content
This repository has been archived by the owner on Mar 22, 2024. It is now read-only.

Only 50 results after fbad_read_creative? #80

Open
lolasbond opened this issue Jan 26, 2018 · 9 comments
Open

Only 50 results after fbad_read_creative? #80

lolasbond opened this issue Jan 26, 2018 · 9 comments
Assignees

Comments

@lolasbond
Copy link

Hi,

I have access to an ad account with a lot going on (we've got hundreds of fb ads and thus hundreds of ad creatives). After running fbad_read_creative(), I'm getting only 50 results? I initialized our main ad account which definitely has a lot of ads associated with it. Is there a kind of default where it only pulls the last month's newest creatives or something? I went through the Marketing API documentation, but I didn't see any limits mentioned on the Read section of the creatives portion.

I might be unpacking it wrong. I'm fairly new at this entire thing, and I'm using unlist and matrix to turn the results into a data frame.

Thanks.

@daroczig
Copy link
Owner

I don't know of and never faced such limitation. Can you share your devtools::session_info()? Also, try data.table::rbindlist instead of unlist & matrix.

@lolasbond lolasbond changed the title Only 25 results after fbad_read_creative? Only 50 results after fbad_read_creative? Jan 26, 2018
@lolasbond
Copy link
Author

Thank you for your quick reply (and for building this tool in the first place)!

I tried data.table::rbindlist, but I run into the error where I have different lengths per item in the list.

Here is my session info output:

Session info ---------------------------------------------------------------------------------------------------------------------------------
setting value
version R version 3.3.2 (2016-10-31)
system x86_64, mingw32
ui RStudio (1.0.136)
language (EN)
collate English_United States.1252
tz America/New_York
date 2018-01-26

Packages -------------------------------------------------------------------------------------------------------------------------------------
package * version date source
base * 3.3.2 2016-10-31 local
bit 1.1-12 2014-04-09 CRAN (R 3.3.2)
bit64 0.9-7 2017-05-08 CRAN (R 3.3.3)
bitops 1.0-6 2013-08-17 CRAN (R 3.3.2)
curl 2.8.1 2017-07-21 CRAN (R 3.3.3)
data.table 1.10.4-3 2017-10-27 CRAN (R 3.3.3)
datasets * 3.3.2 2016-10-31 local
devtools 1.13.4 2017-11-09 CRAN (R 3.3.3)
digest 0.6.12 2017-01-27 CRAN (R 3.3.3)
fbRads * 2.10.0 2017-11-29 Github (90a774b)
futile.logger 1.4.3 2016-07-10 CRAN (R 3.3.3)
futile.options 1.0.0 2010-04-06 CRAN (R 3.3.2)
graphics * 3.3.2 2016-10-31 local
grDevices * 3.3.2 2016-10-31 local
httpuv 1.3.5 2017-07-04 CRAN (R 3.3.3)
httr * 1.3.1 2017-08-20 CRAN (R 3.3.3)
jsonlite * 1.5 2017-06-01 CRAN (R 3.3.3)
lambda.r 1.2 2017-09-16 CRAN (R 3.3.3)
memoise 1.1.0 2017-04-21 CRAN (R 3.3.3)
methods * 3.3.2 2016-10-31 local
plyr 1.8.4 2016-06-08 CRAN (R 3.3.3)
R6 2.2.2 2017-06-17 CRAN (R 3.3.3)
Rcpp 0.12.12 2017-07-15 CRAN (R 3.3.3)
RCurl 1.95-4.8 2016-03-01 CRAN (R 3.3.3)
stats * 3.3.2 2016-10-31 local
tools 3.3.2 2016-10-31 local
utils * 3.3.2 2016-10-31 local
withr 2.0.0 2017-07-28 CRAN (R 3.3.3)

@daroczig
Copy link
Owner

Thanks!

So looking into this, it seems that this function that I wrote quite a while ago tries to achieve multiple things: reading fields of a list of provided creatives and listing creatives under an Ad Account.

For all other similar functions (eg reading/listing Ad Sets or Ad Groups), I've fixed that quite a long time ago by having a read and a list function, see eg fbad_read_ad and fbad_list_ad. This should be done for the creatives as well -- but as I'm not using this for listing, did not realize the problem ...

In short, the problem is that this function is not doing proper paging -- like eg fbad_list_ad.

Adding this to my TODO list, but I won't have time to actively work on it in the near future.

Suggested workaround until then: I'm not sure what you want to achive, but maybe you could list all the creatives by listing all the Ad Groups with the creative field, then hit the FB API with the creative ids to get the fields you are interested in.

@daroczig daroczig self-assigned this Jan 26, 2018
@lolasbond
Copy link
Author

Alright, thanks for the suggestion!

@ErezLo
Copy link

ErezLo commented Sep 14, 2020

Hey

Wondering if there was an update on this issue since then?
I am only getting 25 results.

Thank you for your time

@daroczig
Copy link
Owner

@ErezLo sorry, no related updates in the package due to lack of resources -- but I would highly appreciate a PR as per my above comment if anyone has some time.

@ErezLo
Copy link

ErezLo commented Sep 14, 2020

Thanks @daroczig
Not sure thats what you meant i previous comment but, I tried getting the creative by adgroup but it doesnt seem to be a field that is related to "adset".

Thanks

@ErezLo
Copy link

ErezLo commented Sep 15, 2020

I tried looking here
https://github.com/daroczig/fbRads/blob/master/R/fb_ad.R

and understand to logic behind "fbad_request_next_page" and $paging$next but i dont think I am the person to update the function to work properly and PR it.

Hope someone else will in the future.
Thank you

@ErezLo
Copy link

ErezLo commented Sep 16, 2020

I tried something, @daroczig if that makes sense and you want to update the function that would be great

`#' Read ad creative
#' @inheritParams fbad_request
#' @param id Ad Creative or Ad Set id
#' @param by get all Ad Creatives for the account, for a given Ad or a single Creative
#' @param fields character vector of fields to get from the API
#' @return list to be post-processed
#' @export
#' @references \url{https://developers.facebook.com/docs/marketing-api/reference/ad-creative#Reading}
#' @examples \dontrun{
#' ## get all creatives for the current account
#' fbad_read_creative(fbacc)
#' }
fbad_read_creative <- function(
fbacc, id,
by = c('account', 'creative', 'ad'),
fields = c(
'id', 'name', 'body', 'title', 'run_status',
'actor_id', 'call_to_action_type', 'follow_redirect',
'image_crops', 'image_file', 'image_hash', 'image_url', 'thumbnail_url',
'link_url', 'url_tags',
'object_id', 'object_story_id', 'object_story_spec', 'object_type', 'object_url')) {

fbacc <- fbad_check_fbacc()

by <- match.arg(by)

default to current account id

if (by == 'account' && missing(id)) {
id <- fbacc$account_id
}

get fields

fields <- match.arg(fields, several.ok = TRUE)
fields <- paste(fields, collapse = ',')

we need an id

if (by != 'account' && missing(id))
stop('An id is required.')

get results

res <- fbad_request(fbacc,
path = switch(by,
'creative' = paste0(id, '?fields=', fields),
'account' = paste0('act_', id, '/adcreatives?fields=', fields),
'ad' = paste0(id, '/adcreatives?fields=', fields)),
method = "GET")

return

fromJSONish(res)

or do batched query

res <- lapply(
split(id, 1:length(id) %/% 50),
function(batch) {

  ## query FB by 50 ids at a time
  res <- fbad_request(fbacc,
                      path   = '',
                      params = list(
                        ids    = paste(batch, collapse = ','),
                        fields = fields),
                      method = "GET")
  
  res <- fromJSONish(res)
  if (simplify) {
    res <- rbindlist(lapply(res, as.data.frame, stringsAsFactors = FALSE), fill = TRUE)
  }
  res
  
})

}
`

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants