Giter Site home page Giter Site logo

Comments (9)

daroczig avatar daroczig commented on May 16, 2024

You mean the fb_insights function? As this can do async queries as well, there shouldn't be a limit on the amount of data to be pulled from the Marketing API. How many ads and what time period are you pulling?

from fbrads.

tokumotion avatar tokumotion commented on May 16, 2024

@daroczig I am pulling 30ish campaigns for the lapse of a year. Each campaign should have around 3 ads each.

from fbrads.

daroczig avatar daroczig commented on May 16, 2024

Can you post here a demo function call when you hit the limit and the response from FB? Of course please sanitize the account id, token etc.

from fbrads.

tokumotion avatar tokumotion commented on May 16, 2024

Hi @daroczig, this is my example.

fblista <- fbad_list_campaign(fields = c("id", "name", "objective", 
                                         "start_time","stop_time"))

fblista %<>%
  filter(grepl("brand1|brand2|brand3", fblista$name, 
               ignore.case = TRUE),
         start_time >= "2015-01-01", stop_time <= "2015-12-31")

fblista[,c(4:5)] <- lapply(fblista[,c(4:5)], ymd_hms)

POST_ENGAGEMENT <- filter(fblista, objective == "POST_ENGAGEMENT")

How does POST_ENGAGEMENT look like?

> dim(POST_ENGAGEMENT)
[1] 56  5

This is where I find some troubles, if I go with job_type = "async":

> fb_insights(target = POST_ENGAGEMENT$id,
 +             fields = c("impressions", "social_impressions", "clicks", 
 +                        "social_clicks", "spend", "website_clicks",
 +                        "reach", "ctr", "unique_ctr", "cpc", "cpm",
 +                        "cpp"), job_type = c("async"))

I get this error:

 Error in fb_insights(target = POST_ENGAGEMENT$id, fields = c("impressions",  : 
  Batched queries are not possible with async call. Please query only one item at a time.

If I go with job_type=c("sync")

> test <– fb_insights(target = POST_ENGAGEMENT$id,
 +             fields = c("impressions", "social_impressions", "clicks", 
 +                        "social_clicks", "spend", "website_clicks",
 +                        "reach", "ctr", "unique_ctr", "cpc", "cpm",
 +                        "cpp"), job_type = c("sync"))

I don't get all the data I made a query for (dim() should be returning 56 rows):

> dim(test$`0`)
[1]  4 14

from fbrads.

daroczig avatar daroczig commented on May 16, 2024

What about querying all your campaigns in your FB account for a time period (using eg date_preset or date ranges) instead of passing a list of campaign ids (by omitting the target parameter)? That should work with the async methods as well.

Another option could be doing separate queries, something like:

lapply(POST_ENGAGEMENT$id,
       function(id)
       fb_insights(target = id,
                   fields = c("impressions", "social_impressions", "clicks",
                              "social_clicks", "spend", "website_clicks",
                              "reach", "ctr", "unique_ctr", "cpc", "cpm",
                              "cpp"), job_type = "async"))

Then calling rbindlist from data.table or similar on the results.

from fbrads.

tokumotion avatar tokumotion commented on May 16, 2024

I'm getting this:

test_2 <- lapply(POST_ENGAGEMENT$id,
   function(id) fb_insights(target = id,
                 fields = toJSON(c("impressions", "social_impressions", 
                            "clicks",
                            "social_clicks", "spend", "website_clicks",
                            "reach", "ctr", "unique_ctr", "cpc", "cpm",
                            "cpp"), job_type = "async")))

This is returns a list with each campaign's insights.

Note that the original code would return error if you don't convert the fields toJSON().

from fbrads.

daroczig avatar daroczig commented on May 16, 2024

So it works, @tokumotion? If you have the list, you should be able to merge those together via rbindlist from data.table or do.call and rbind, right?

from fbrads.

tokumotion avatar tokumotion commented on May 16, 2024

@daroczig Yes, it works. I'm currently working on a way to convert the results into a data frame. Thank you!

This code converts the outcome into a dataframe:

test_2 <- do.call("rbind", lapply(test_2, data.frame))

There is something I don't quite get, if you see the code I placed, the toJSON() function encloses the job_type = "async"parameter. Running this code will return the desired outcome. However, if you let job_type="async" out (as one would intuitively would), the code returns this error:

> test_2 <- lapply(POST_ENGAGEMENT$id,
+        function(id) fb_insights(target = id, 
+                                 fields = toJSON(c("impressions", 
+                                                   "social_impressions", 
+                                                   "clicks", "social_clicks", 
+                                                   "spend", "website_clicks",
+                                                   "reach", "ctr", 
+                                                   "unique_ctr", "cpc", 
+                                                   "cpm", "cpp")), 
+                                 job_type = "async"))

Error:

Error: Argument 'txt' must be a JSON string, URL or file.
Called from: base::stop(..., call. = FALSE)

Why would you have to insert job_type="async"into the JSON file?

from fbrads.

daroczig avatar daroczig commented on May 16, 2024

Sounds good, thanks for the feedback -- I am closing this ticket. Can you please open a new ticket for the job_type issue with a minimal example?

from fbrads.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.