问题描述
我正在尝试创建一个再营销 userList,使用 Google Ads Api 的 Java 实现将一些用户添加到其中。
自定义受众创建部分看起来不错,我可以看到它在广告平台中创建,但看起来用户没有包含在其中。
Print screen: Empty custom audience inside google ads plataform
我发送了一个以 2000 个用户为参数的 JsonArray,并在此函数中对其进行散列,并使用 this samples 作为参考。
我不确定我是否误解了 the documentation 或者我是否以错误的方式或类似的方式包含了 userList。
public JsonArray uploadJsonList(String customerId,JsonArray jsonUsers) throws Exception {
List<Member> members = new ArrayList<>();
JsonObject hashedobj = new JsonObject();
JsonArray arrayJsonHashed = new JsonArray();
for (JsonValue jsonValue : jsonUsers) {
JsonObject obj = jsonValue.asObject();
hashedobj = new JsonObject();
//Getting user data
String normalizedEmail = textUtils.tonormalizedString(obj.get("PESSOA_EMAIL1").toString());
String normalizedPhone = textUtils.tonormalizedString(obj.get("PESSOA_CELULAR").toString());
String normalizedId = obj.get("PESSOA_ID").toString();
normalizedId = removeFirstandLast(normalizedId);
//Hashing user data
hashedobj.add("pessoa_email1",textUtils.toSHA256String(normalizedEmail));
hashedobj.add("pessoa_celular",textUtils.toSHA256String(normalizedPhone));
hashedobj.add("pessoa_id",normalizedId);
arrayJsonHashed.add(hashedobj);
//Creating a member list
Member member = new Member();
member.setHashedEmail(textUtils.toSHA256String(normalizedEmail));
member.setHashedPhoneNumber(textUtils.toSHA256String(normalizedPhone));
members.add(member);
}
//starting ads services
AdWordsServices adWordsServices = new AdWordsServices();
Customer[] customers = getCustomers(adWordsServices,session);
session.setClientCustomerId(customerId);
AdwordsUserListServiceInterface userListService = adWordsServices.get(session,AdwordsUserListServiceInterface.class);
// Create a user list.
CrmBasedUserList userList = new CrmBasedUserList();
userList.setName("Test Remarketing Custom Audience - " + System.currentTimeMillis());
userList.setDescription("A list of customers that was readed from big query");
// CRM-based user lists can use a membershipLifeSpan of 10000 to indicate unlimited; otherwise
// normal values apply.
userList.setMembershipLifeSpan(100L);
userList.setUploadKeyType(CustomerMatchUploadKeyType.CONTACT_INFO);
// Create operation.
UserListOperation operation = new UserListOperation();
operation.setoperand(userList);
operation.setoperator(Operator.ADD);
// Add user list.
UserListReturnValue result = userListService.mutate(new UserListOperation[]{operation});
// display user list.
UserList userListAdded = result.getValue(0);
System.out.printf(
"User list with name '%s' and ID %d was added.%n",userListAdded.getName(),userListAdded.getId());
// Get user list ID.
Long userListId = userListAdded.getId();
// Create operation to add members to the user list based on email addresses.
MutateMembersOperation mutateMembersOperation = new MutateMembersOperation();
MutateMembersOperand operand = new MutateMembersOperand();
operand.setUserListId(userListId);
operand.setMembersList(members.toArray(new Member[members.size()]));
mutateMembersOperation.setoperand(operand);
mutateMembersOperation.setoperator(Operator.ADD);
// Add members to the user list based on email addresses.
MutateMembersReturnValue mutateMembersResult =
userListService.mutateMembers(new MutateMembersOperation[]{mutateMembersOperation});
// display results.
// Reminder: it may take several hours for the list to be populated with members.
for (UserList userListResult : mutateMembersResult.getUserLists()) {
System.out.printf(
"%d email addresses were uploaded to user list with name '%s' and ID %d "
+ "and are scheduled for review.%n",members.size(),userListResult.getName(),userListResult.getId());
}
return arrayJsonHashed;
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)