Skip to content

Commit bb3f1df

Browse files
satwikareddy3facebook-github-bot
authored andcommitted
Auto-generated java SDK code update
Summary: ignore-conflict-markers Reviewed By: honz Differential Revision: D76757473 fbshipit-source-id: eb0b3a623753fd5750f48e5c6269f15ad32bfa85
1 parent 308e048 commit bb3f1df

105 files changed

Lines changed: 13776 additions & 2582 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
import com.facebook.ads.sdk.APIContext;
10+
import com.facebook.ads.sdk.APIException;
11+
import com.facebook.ads.sdk.serverside.ActionSource;
12+
import com.facebook.ads.sdk.serverside.CustomData;
13+
import com.facebook.ads.sdk.serverside.DeliveryCategory;
14+
import com.facebook.ads.sdk.serverside.Event;
15+
import com.facebook.ads.sdk.serverside.EventRequest;
16+
import com.facebook.ads.sdk.serverside.EventResponse;
17+
import com.facebook.ads.sdk.serverside.UserData;
18+
19+
import java.util.Arrays;
20+
21+
public class ServerSideApiExample {
22+
23+
public static final String ACCESS_TOKEN = "<ACCESS_TOKEN>";
24+
public static final String PIXEL_ID = "<ADS_PIXEL_ID>";
25+
26+
public static void main(String[] args) {
27+
APIContext context = new APIContext(ACCESS_TOKEN).enableDebug(true);
28+
context.setLogger(System.out);
29+
30+
UserData userData = new UserData()
31+
.emails(Arrays.asList("joe@eg.com"))
32+
.phones(Arrays.asList("12345678901", "14251234567"))
33+
.lead_id("525645896321548");
34+
35+
Map<String, String> propertyBag = new HashMap<>();
36+
propertyBag.put("lead_event_source", "Salesforce");
37+
38+
CustomData customData = new CustomData()
39+
.customProperties(propertyBag);
40+
41+
Event purchaseEvent = new Event();
42+
purchaseEvent.eventName("QualifiedLead")
43+
.eventTime(System.currentTimeMillis() / 1000L)
44+
.userData(userData)
45+
.customData(customData)
46+
.actionSource(ActionSource.system_generated);
47+
48+
EventRequest eventRequest = new EventRequest(PIXEL_ID, context);
49+
eventRequest.addDataItem(purchaseEvent);
50+
51+
try {
52+
EventResponse response = eventRequest.execute();
53+
System.out.println(String.format("Standard API response : %s ", response));
54+
} catch (APIException e) {
55+
e.printStackTrace();
56+
}
57+
}
58+
}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>com.facebook.business.sdk</groupId>
55
<artifactId>facebook-java-business-sdk</artifactId>
66
<packaging>jar</packaging>
7-
<version>22.0.3</version>
7+
<version>23.0.0</version>
88
<name>${project.groupId}:${project.artifactId}</name>
99
<description>Facebook Business Solutions SDK for Java</description>
1010
<url>https://developers.facebook.com/docs/marketing-api/sdks</url>
Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
package com.facebook.ads.sdk;
10+
11+
import java.io.File;
12+
import java.lang.reflect.Modifier;
13+
import java.lang.reflect.Type;
14+
import java.util.Arrays;
15+
import java.util.HashMap;
16+
import java.util.List;
17+
import java.util.Map;
18+
19+
import com.google.common.base.Function;
20+
import com.google.common.util.concurrent.Futures;
21+
import com.google.common.util.concurrent.ListenableFuture;
22+
import com.google.common.util.concurrent.MoreExecutors;
23+
import com.google.common.util.concurrent.SettableFuture;
24+
import com.google.gson.JsonObject;
25+
import com.google.gson.JsonArray;
26+
import com.google.gson.annotations.SerializedName;
27+
import com.google.gson.reflect.TypeToken;
28+
import com.google.gson.Gson;
29+
import com.google.gson.GsonBuilder;
30+
import com.google.gson.JsonElement;
31+
import com.google.gson.JsonParser;
32+
33+
import com.facebook.ads.sdk.APIException.MalformedResponseException;
34+
35+
/**
36+
* This class is auto-generated.
37+
*
38+
* For any issues or feature requests related to this class, please let us know
39+
* on github and we'll fix in our codegen framework. We'll not be able to accept
40+
* pull request for this class.
41+
*
42+
*/
43+
public class AIGeneratedProductImage extends APINode {
44+
@SerializedName("flagged_for_manual_review")
45+
private Boolean mFlaggedForManualReview = null;
46+
@SerializedName("transformed_image_url")
47+
private String mTransformedImageUrl = null;
48+
protected static Gson gson = null;
49+
50+
public AIGeneratedProductImage() {
51+
}
52+
53+
public String getId() {
54+
return null;
55+
}
56+
public static AIGeneratedProductImage loadJSON(String json, APIContext context, String header) {
57+
AIGeneratedProductImage aiGeneratedProductImage = getGson().fromJson(json, AIGeneratedProductImage.class);
58+
if (context.isDebug()) {
59+
JsonParser parser = new JsonParser();
60+
JsonElement o1 = parser.parse(json);
61+
JsonElement o2 = parser.parse(aiGeneratedProductImage.toString());
62+
if (o1.getAsJsonObject().get("__fb_trace_id__") != null) {
63+
o2.getAsJsonObject().add("__fb_trace_id__", o1.getAsJsonObject().get("__fb_trace_id__"));
64+
}
65+
if (!o1.equals(o2)) {
66+
context.log("[Warning] When parsing response, object is not consistent with JSON:");
67+
context.log("[JSON]" + o1);
68+
context.log("[Object]" + o2);
69+
}
70+
}
71+
aiGeneratedProductImage.context = context;
72+
aiGeneratedProductImage.rawValue = json;
73+
aiGeneratedProductImage.header = header;
74+
return aiGeneratedProductImage;
75+
}
76+
77+
public static APINodeList<AIGeneratedProductImage> parseResponse(String json, APIContext context, APIRequest request, String header) throws MalformedResponseException {
78+
APINodeList<AIGeneratedProductImage> aiGeneratedProductImages = new APINodeList<AIGeneratedProductImage>(request, json, header);
79+
JsonArray arr;
80+
JsonObject obj;
81+
JsonParser parser = new JsonParser();
82+
Exception exception = null;
83+
try{
84+
JsonElement result = parser.parse(json);
85+
if (result.isJsonArray()) {
86+
// First, check if it's a pure JSON Array
87+
arr = result.getAsJsonArray();
88+
for (int i = 0; i < arr.size(); i++) {
89+
aiGeneratedProductImages.add(loadJSON(arr.get(i).getAsJsonObject().toString(), context, header));
90+
};
91+
return aiGeneratedProductImages;
92+
} else if (result.isJsonObject()) {
93+
obj = result.getAsJsonObject();
94+
if (obj.has("data")) {
95+
if (obj.has("paging")) {
96+
JsonObject paging = obj.get("paging").getAsJsonObject();
97+
if (paging.has("cursors")) {
98+
JsonObject cursors = paging.get("cursors").getAsJsonObject();
99+
String before = cursors.has("before") ? cursors.get("before").getAsString() : null;
100+
String after = cursors.has("after") ? cursors.get("after").getAsString() : null;
101+
aiGeneratedProductImages.setCursors(before, after);
102+
}
103+
String previous = paging.has("previous") ? paging.get("previous").getAsString() : null;
104+
String next = paging.has("next") ? paging.get("next").getAsString() : null;
105+
aiGeneratedProductImages.setPaging(previous, next);
106+
if (context.hasAppSecret()) {
107+
aiGeneratedProductImages.setAppSecret(context.getAppSecretProof());
108+
}
109+
}
110+
if (obj.get("data").isJsonArray()) {
111+
// Second, check if it's a JSON array with "data"
112+
arr = obj.get("data").getAsJsonArray();
113+
for (int i = 0; i < arr.size(); i++) {
114+
aiGeneratedProductImages.add(loadJSON(arr.get(i).getAsJsonObject().toString(), context, header));
115+
};
116+
} else if (obj.get("data").isJsonObject()) {
117+
// Third, check if it's a JSON object with "data"
118+
obj = obj.get("data").getAsJsonObject();
119+
boolean isRedownload = false;
120+
for (String s : new String[]{"campaigns", "adsets", "ads"}) {
121+
if (obj.has(s)) {
122+
isRedownload = true;
123+
obj = obj.getAsJsonObject(s);
124+
for (Map.Entry<String, JsonElement> entry : obj.entrySet()) {
125+
aiGeneratedProductImages.add(loadJSON(entry.getValue().toString(), context, header));
126+
}
127+
break;
128+
}
129+
}
130+
if (!isRedownload) {
131+
aiGeneratedProductImages.add(loadJSON(obj.toString(), context, header));
132+
}
133+
}
134+
return aiGeneratedProductImages;
135+
} else if (obj.has("images")) {
136+
// Fourth, check if it's a map of image objects
137+
obj = obj.get("images").getAsJsonObject();
138+
for (Map.Entry<String, JsonElement> entry : obj.entrySet()) {
139+
aiGeneratedProductImages.add(loadJSON(entry.getValue().toString(), context, header));
140+
}
141+
return aiGeneratedProductImages;
142+
} else {
143+
// Fifth, check if it's an array of objects indexed by id
144+
boolean isIdIndexedArray = true;
145+
for (Map.Entry entry : obj.entrySet()) {
146+
String key = (String) entry.getKey();
147+
if (key.equals("__fb_trace_id__")) {
148+
continue;
149+
}
150+
JsonElement value = (JsonElement) entry.getValue();
151+
if (
152+
value != null &&
153+
value.isJsonObject() &&
154+
value.getAsJsonObject().has("id") &&
155+
value.getAsJsonObject().get("id") != null &&
156+
value.getAsJsonObject().get("id").getAsString().equals(key)
157+
) {
158+
aiGeneratedProductImages.add(loadJSON(value.toString(), context, header));
159+
} else {
160+
isIdIndexedArray = false;
161+
break;
162+
}
163+
}
164+
if (isIdIndexedArray) {
165+
return aiGeneratedProductImages;
166+
}
167+
168+
// Sixth, check if it's pure JsonObject
169+
aiGeneratedProductImages.clear();
170+
aiGeneratedProductImages.add(loadJSON(json, context, header));
171+
return aiGeneratedProductImages;
172+
}
173+
}
174+
} catch (Exception e) {
175+
exception = e;
176+
}
177+
throw new MalformedResponseException(
178+
"Invalid response string: " + json,
179+
exception
180+
);
181+
}
182+
183+
@Override
184+
public APIContext getContext() {
185+
return context;
186+
}
187+
188+
@Override
189+
public void setContext(APIContext context) {
190+
this.context = context;
191+
}
192+
193+
@Override
194+
public String toString() {
195+
return getGson().toJson(this);
196+
}
197+
198+
199+
public Boolean getFieldFlaggedForManualReview() {
200+
return mFlaggedForManualReview;
201+
}
202+
203+
public AIGeneratedProductImage setFieldFlaggedForManualReview(Boolean value) {
204+
this.mFlaggedForManualReview = value;
205+
return this;
206+
}
207+
208+
public String getFieldTransformedImageUrl() {
209+
return mTransformedImageUrl;
210+
}
211+
212+
public AIGeneratedProductImage setFieldTransformedImageUrl(String value) {
213+
this.mTransformedImageUrl = value;
214+
return this;
215+
}
216+
217+
218+
219+
220+
synchronized /*package*/ static Gson getGson() {
221+
if (gson != null) {
222+
return gson;
223+
} else {
224+
gson = new GsonBuilder()
225+
.excludeFieldsWithModifiers(Modifier.STATIC)
226+
.excludeFieldsWithModifiers(Modifier.PROTECTED)
227+
.disableHtmlEscaping()
228+
.create();
229+
}
230+
return gson;
231+
}
232+
233+
public AIGeneratedProductImage copyFrom(AIGeneratedProductImage instance) {
234+
this.mFlaggedForManualReview = instance.mFlaggedForManualReview;
235+
this.mTransformedImageUrl = instance.mTransformedImageUrl;
236+
this.context = instance.context;
237+
this.rawValue = instance.rawValue;
238+
return this;
239+
}
240+
241+
public static APIRequest.ResponseParser<AIGeneratedProductImage> getParser() {
242+
return new APIRequest.ResponseParser<AIGeneratedProductImage>() {
243+
public APINodeList<AIGeneratedProductImage> parseResponse(String response, APIContext context, APIRequest<AIGeneratedProductImage> request, String header) throws MalformedResponseException {
244+
return AIGeneratedProductImage.parseResponse(response, context, request, header);
245+
}
246+
};
247+
}
248+
}

src/main/java/com/facebook/ads/sdk/ALMGuidance.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public class ALMGuidance extends APINode {
4545
private String mAdAccountId = null;
4646
@SerializedName("guidances")
4747
private List<Object> mGuidances = null;
48+
@SerializedName("opportunity_score")
49+
private Double mOpportunityScore = null;
4850
@SerializedName("parent_advertiser_id")
4951
private String mParentAdvertiserId = null;
5052
@SerializedName("parent_advertiser_name")
@@ -218,6 +220,15 @@ public ALMGuidance setFieldGuidances(List<Object> value) {
218220
return this;
219221
}
220222

223+
public Double getFieldOpportunityScore() {
224+
return mOpportunityScore;
225+
}
226+
227+
public ALMGuidance setFieldOpportunityScore(Double value) {
228+
this.mOpportunityScore = value;
229+
return this;
230+
}
231+
221232
public String getFieldParentAdvertiserId() {
222233
return mParentAdvertiserId;
223234
}
@@ -255,6 +266,7 @@ public ALMGuidance setFieldParentAdvertiserName(String value) {
255266
public ALMGuidance copyFrom(ALMGuidance instance) {
256267
this.mAdAccountId = instance.mAdAccountId;
257268
this.mGuidances = instance.mGuidances;
269+
this.mOpportunityScore = instance.mOpportunityScore;
258270
this.mParentAdvertiserId = instance.mParentAdvertiserId;
259271
this.mParentAdvertiserName = instance.mParentAdvertiserName;
260272
this.context = instance.context;

0 commit comments

Comments
 (0)