facebook-java-business-sdk
facebook-java-business-sdk copied to clipboard
Getting com.facebook.ads.sdk.APIException$MalformedResponseException while fetching ad insights
Which SDK version are you using?
10.0.0
What's the issue?
While trying to fetch ad insights application fails with following exception :
com.facebook.ads.sdk.APIException$MalformedResponseException: Invalid response string:
Steps/Sample code to reproduce the issue
APIRequestGetInsightsAsync getInsightsAsync = adAccount.getInsightsAsync()
.setLevel(adLevel) // Ad level by default
.setFields(fields) // selected fields or all
.setActionReportTime(actionReportTime) // selected in source
.setBreakdowns(breakdownsList) // Empty when not required
.setTimeIncrement("1") // to fetch the records on a granular level of per-day
.setTimeRange(FacebookAdsUtils.getTimeRange(startDate, endDate));
AdReportRun adReportRun = getInsightsAsync.execute();
Observed Results:
- What happened? This could be a description, log output, etc. While trying to fetch the result sdk code breaks inside parseResponse method (AdsInsights.java:357). Following is the exception that we see :
at com.facebook.ads.sdk.AdsInsights.parseResponse(AdsInsights.java:457)
at com.facebook.ads.sdk.AdReportRun$APIRequestGetInsights.parseResponse(AdReportRun.java:515)
at com.facebook.ads.sdk.AdReportRun$APIRequestGetInsights.execute(AdReportRun.java:526)
at com.facebook.ads.sdk.AdReportRun$APIRequestGetInsights.execute(AdReportRun.java:520)
We noticed that mInstantExperienceOutboundClicks is of type List<AdsActionStats>. But the json string somehow doesn't seem to adhere to the Type defined.
If we go down the trace further this is what we see :
Caused by: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected a string but was
BEGIN_ARRAY at line 1 column 638 path $.instant_experience_outbound_clicks
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:226)
at com.google.gson.Gson.fromJson(Gson.java:932)
at com.google.gson.Gson.fromJson(Gson.java:897)
at com.google.gson.Gson.fromJson(Gson.java:846)
at com.google.gson.Gson.fromJson(Gson.java:817)
at com.facebook.ads.sdk.AdsInsights.loadJSON(AdsInsights.java:337)
at com.facebook.ads.sdk.AdsInsights.parseResponse(AdsInsights.java:394)
... 29 common frames omitted
Caused by: java.lang.IllegalStateException: Expected a string but was BEGIN_ARRAY at line 1 column 638 path
$.instant_experience_outbound_clicks
at com.google.gson.stream.JsonReader.nextString(JsonReader.java:826)
at com.google.gson.internal.bind.TypeAdapters$16.read(TypeAdapters.java:402)
at com.google.gson.internal.bind.TypeAdapters$16.read(TypeAdapters.java:390)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:131)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:222)
... 35 common frames omitted
Expected Results:
- What did you expect to happen? Code should be able to parse all the fields coming as part of ad insights.
This is also happening in v9.0.0. It appears to be a breaking change made to the API and is in the code for v11.0.0 but that jar is not published to Maven yet due to #347
I see. Thanks for the update @galacticgumshoe. I hope this doesn't get a lot of time to get resolved as we already have the code ready for v11.0.0.
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.