redwulf
redwulf

Reputation: 1317

Batch Requests for Insights on Facebook Marketing API (JAVA)

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.

Upvotes: 2

Views: 1114

Answers (1)

redwulf
redwulf

Reputation: 1317

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()

Upvotes: 2

Related Questions