I'm trying to get the clicks, spend, and conversions from an Ad Account over a certain time frame, so I downloaded sample code from FB to do so. After a few adjustments I was able to get it running, but it only prints the clicks and spend.
I believe it has to do with the clicks and spend being listed as "numeric Strings", while the conversions are listed as "list" (see here: https://developers.facebook.com/docs/marketing-api/insights/parameters#fields). I'm not sure how to get this to print the value, when I add .toString() to the conversions, it prints this: com.facebook.ads.sdk.AdAccount$APIRequestGetInsights@5ccd43c2.
This is the code I have currently:
import com.facebook.ads.sdk.*;
import com.facebook.ads.sdk.AdAccount.APIRequestGetInsights;
import java.io.File;
import java.util.Arrays;
import java.util.List;
public class SAMPLE_CODE {
public static void main (String args[]) throws APIException {
String access_token = "xxx";
String ad_account_id = "xxx";
String app_secret = "xxx";
String app_id = "xxx";
APIContext context = new APIContext(access_token, app_secret).enableDebug(true);
AdAccount account = new AdAccount(ad_account_id, context);
account.getInsights()
.setLevel(AdsInsights.EnumLevel.VALUE_ACCOUNT)
.setFiltering("[]")
.setBreakdowns(Arrays.asList())
.setTimeRange("{\"since\":\"2019-07-15\",\"until\":\"2019-07-15\"}")
.requestField("clicks")
.requestField("spend")
.requestField("conversions")
.execute();
}
}