facebook / facebook-java-business-sdk

Java SDK for Meta Marketing APIs
https://developers.facebook.com/docs/business-sdk
Other
402 stars 332 forks source link

Breakdown fields and its getters (like getFieldAge(), getFieldCountry(), etc) from Java SDK AdsInsights class are removed #298

Closed afsalviz closed 4 years ago

afsalviz commented 4 years ago

SDK version: v7.0.0

engagement insight is queried with certain breakdown parameters like age, country, gender, etc. and this breakdown field is returned in the insight response as well. but the behavior has changed when queried through Java API v7.0

when I was trying to upgrade from v5.0 to v7.0 the class AdsInsights.java is not having those breakdown param class member variables anymore, the breakdown field getters (like getFieldAge(), getFieldCountry()..., etc) from AdsInsights class are removed as per following commit https://github.com/facebook/facebook-java-business-sdk/commit/7d3f1f8dfa4eb6780f5cc09c6156d1f79a4e0e62#diff-1bbe1352f250c4812271431dc9f55509. (File: src/main/java/com/facebook/ads/sdk/AdsInsights.java) but they are still returned if queried through curl / FB Explorer

was it done intentionally? (or) is there any alternate way of querying it through Java SDK

Steps/Sample code to reproduce the issue

call from Java SDK

String facebookEngagementId = "<engagement_id>";
Date fromDate = null, toDate = null;
try {
    fromDate = (new SimpleDateFormat("yyyy-MM-dd")).parse("2020-05-15");
    toDate = (new SimpleDateFormat("yyyy-MM-dd")).parse("2020-05-20");
} catch (ParseException e) {
    e.printStackTrace();
}
String type = "age";

SimpleDateFormat insights_date_format = new SimpleDateFormat("yyyy-MM-dd");

List<String> fields = new ArrayList<>(
        Arrays.asList("impressions", "ctr", "clicks", "reach", "frequency", "spend", "cpc"));
Campaign campaign = new Campaign(facebookEngagementId,<context>);
JSONObject dateObject = new JSONObject();
dateObject.put("since", insights_date_format.format(fromDate));
dateObject.put("until", insights_date_format.format(toDate));

APINodeList<AdsInsights> insightsList = null;
try {
    insightsList = campaign.getInsights().setBreakdowns("age")
                    .setTimeRange(dateObject.toString()).requestFields(fields).setSort("clicks_descending").execute();
} catch (APIException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

the above call on campaign.getInsights() is returning the expected result, but when the mapping to APINodeList<AdsInsights> insightList ignores the breakdown("age") field

Observed Results:

expecting the JSON response to AdInsights object mapping to have breakdown field(in this case it is age)

[JSON]{"impressions":"50077","ctr":"0.984484","clicks":"493","reach":"37936","frequency":"1.320039","spend":"306.84","cpc":"0.622394","date_start":"2020-05-15","date_stop":"2020-05-20","age":"18-24"}
[Object]{"clicks":"493","cpc":"0.622394","ctr":"0.984484","date_start":"2020-05-15","date_stop":"2020-05-20","frequency":"1.320039","impressions":"50077","reach":"37936","spend":"306.84"}

age is ignored while mapping AdInsights object

Expected Results:

[JSON]{"impressions":"50077","ctr":"0.984484","clicks":"493","reach":"37936","frequency":"1.320039","spend":"306.84","cpc":"0.622394","date_start":"2020-05-15","date_stop":"2020-05-20","age":"18-24"}
[Object]{"clicks":"493","cpc":"0.622394","ctr":"0.984484","date_start":"2020-05-15","date_stop":"2020-05-20","frequency":"1.320039","impressions":"50077","reach":"37936","spend":"306.84","age":"18-24"}
FluencyMatt commented 4 years ago

The device_platform breakdown field is missing as well

stale[bot] commented 4 years ago

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 4 years ago

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.