Comments (9)
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.
@daroczig I am pulling 30ish campaigns for the lapse of a year. Each campaign should have around 3 ads each.
from fbrads.
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.
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.
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.
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.
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.
@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.
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)
- Can't get all the data with fb_insights HOT 2
- fb_insights issue whenever I use breakdowns parameters HOT 4
- special_ad_categories required to create campaign in new API HOT 3
- Difference in accountid # in fbad_request HOT 2
- fbad_init issue HOT 9
- Possibility to create copies of entities? HOT 2
- fbad_add_audience error with schema using multiple columns
- fb_insights Breakdown Platform Position Error HOT 1
- fb_insights "platform_position" Breakdown Error HOT 1
- fb_insights only fetches last breakdown value HOT 1
- Issue with fbad_get_my_ad_accounts() HOT 1
- Request - Ad Rules Management HOT 3
- new fbad_init issue HOT 5
- threw a bug... HOT 2
- Cannot extract converted_product_value HOT 2
- Unsupported get request. Object with ID 'vhttps:' does not exist HOT 10
- Unable to pull ad account data
- audience_count has been changed from a value to a range (two fields" "approximate_count_lower_bound" and "approximate_count_upper_bound") HOT 2
- Requests stopped working yesterday with v15 HOT 6
- Error when requesting "actions" field HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fbrads.