Comments (2)
To create and update the custom audience, we need to construct the payload of the custom audience update request. For details about updating the custom audience, you can check https://developers.intern.facebook.com/docs/marketing-api/reference/custom-audience/users/
Here's some sample code you can refer to. I use JsonObject/Array to construct the payload.
AdAccount account = new AdAccount(ACCOUNT_ID, context);
CustomAudience audience = account.createCustomAudience()
.setName("Java SDK Test Custom Audience")
.setDescription("Test Audience")
.setSubtype(EnumSubtype.VALUE_CUSTOM)
.execute();
// Audience payload schema
JsonArray schema = new JsonArray();
schema.add(new JsonPrimitive("EMAIL_SHA256"));
schema.add(new JsonPrimitive("PHONE_SHA256"));
// Audience payload data
JsonArray personA = new JsonArray();
personA.add(new JsonPrimitive(sha256("[email protected]")));
personA.add(new JsonPrimitive(sha256("1234567890")));
JsonArray personB = new JsonArray();
personB.add(new JsonPrimitive(sha256("[email protected]")));
personB.add(new JsonPrimitive(sha256("1234567890")));
JsonArray personC = new JsonArray();
personC.add(new JsonPrimitive(sha256("[email protected]")));
personC.add(new JsonPrimitive(sha256("1234567890")));
JsonArray data = new JsonArray();
data.add(personA);
data.add(personB);
data.add(personC);
JsonObject payload = new JsonObject();
payload.add("schema", schema);
payload.add("data", data);
audience.createUser()
.setPayload(payload.toString())
.execute();
public static String sha256(String message) {
try {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] hash = digest.digest(message.getBytes(StandardCharsets.UTF_8));
return toHex(hash);
} catch(Exception e){
return null;
}
}
public static String toHex(byte[] bytes) {
StringBuilder sb = new StringBuilder();
for (byte b : bytes) {
sb.append(String.format("%1$02x", b));
}
return sb.toString();
}
from facebook-java-business-sdk.
Alright. Thank you very much.
from facebook-java-business-sdk.
Related Issues (20)
- Create Leads via APIs
- create AdCreatives erros
- i can not down this sdk HOT 4
- I only have accesstoken and appid appsecert how to obtain user information HOT 3
- Getting "Two factor authentication required" when generating an admin user system access token. HOT 1
- Two factor authentication required. User have to enter a code from SMS or TOTP code generator to pass 2fac. HOT 4
- adSet/reach-estimate does not exist in SDK HOT 1
- AdsInsights gives json parse error when fetching breakdown link_url_asset HOT 5
- Application does not have permission for this action, Please retry this action in a few minutes
- Futures.addCallback is deprecated HOT 3
- Create adset failed
- Create adset failed
- Add `depends_on` support for Batch Request HOT 1
- Async Insights - Exception while parsing image_asset field HOT 3
- lead fetch fail
- Missing `targeting_automation` field in Targeting HOT 2
- AdCreative with `asset_feed_spec` is not creating the Ad with Website destination HOT 1
- not compatible with latest guava HOT 1
- Why the `VALUE_MAXIMUM ` has been replaced with `VALUE_LIFETIME` in AdsInsights.EnumDatePreset in v19.0.1? HOT 5
- There is no Summary attribute on Insights and Campaigns
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from facebook-java-business-sdk.