2

This should be really easy looking at FB documentation for the marketing api but the page is completely empty: https://developers.facebook.com/docs/marketing-api/asyncrequests/v2.10

Does anyone has a simple example on how to make an easy batch request for AdsInsights for Ads, Adsets or Campaigns?

Googling around I find only examples in js or python, so I can't seem to find the right class name in java to do this.

redwulf
  • 1,317
  • 3
  • 13
  • 35

1 Answers1

2

Ok, got it working. Code is in scala but should be the same in java.

implicit val batch = new BatchRequest(FacebookApi.context)
apiNodeList.asScala.map(getInsights)

def getInsights(node: Ad)(implicit data: InsightData, batch: BatchRequest) = {
    node.getInsights
      .setBreakdowns(data.breakdowns)
      .setDatePreset(data.datePreset.toString)
      .setFields(data.fields)
      .setActionAttributionWindows(data.attributionWindow)
      .setTimeIncrement(data.timeIncrement)
      .addToBatch(batch)
}

val result = batch.execute()
redwulf
  • 1,317
  • 3
  • 13
  • 35
  • Hi Redwulf, how did you handle the result which is returned from the batch, where it has paging, cursor, next etc? I found I could not further process the data, while using the python sdk at least. I had posted my question details in Here : https://stackoverflow.com/a/68813247 Also. – soMuchToLearnAndShare Sep 08 '21 at 06:11