本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
CreateCampaign
搭配使用 AWS SDK
以下代码示例演示如何使用 CreateCampaign
。
- Java
-
- SDK适用于 Java 2.x
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 创建市场活动。
import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.pinpoint.PinpointClient; import software.amazon.awssdk.services.pinpoint.model.CampaignResponse; import software.amazon.awssdk.services.pinpoint.model.Message; import software.amazon.awssdk.services.pinpoint.model.Schedule; import software.amazon.awssdk.services.pinpoint.model.Action; import software.amazon.awssdk.services.pinpoint.model.MessageConfiguration; import software.amazon.awssdk.services.pinpoint.model.WriteCampaignRequest; import software.amazon.awssdk.services.pinpoint.model.CreateCampaignResponse; import software.amazon.awssdk.services.pinpoint.model.CreateCampaignRequest; import software.amazon.awssdk.services.pinpoint.model.PinpointException; /** * Before running this Java V2 code example, set up your development * environment, including your credentials. * * For more information, see the following documentation topic: * * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html */ public class CreateCampaign { public static void main(String[] args) { final String usage = """ Usage: <appId> <segmentId> Where: appId - The ID of the application to create the campaign in. segmentId - The ID of the segment to create the campaign from. """; if (args.length != 2) { System.out.println(usage); System.exit(1); } String appId = args[0]; String segmentId = args[1]; PinpointClient pinpoint = PinpointClient.builder() .region(Region.US_EAST_1) .build(); createPinCampaign(pinpoint, appId, segmentId); pinpoint.close(); } public static void createPinCampaign(PinpointClient pinpoint, String appId, String segmentId) { CampaignResponse result = createCampaign(pinpoint, appId, segmentId); System.out.println("Campaign " + result.name() + " created."); System.out.println(result.description()); } public static CampaignResponse createCampaign(PinpointClient client, String appID, String segmentID) { try { Schedule schedule = Schedule.builder() .startTime("IMMEDIATE") .build(); Message defaultMessage = Message.builder() .action(Action.OPEN_APP) .body("My message body.") .title("My message title.") .build(); MessageConfiguration messageConfiguration = MessageConfiguration.builder() .defaultMessage(defaultMessage) .build(); WriteCampaignRequest request = WriteCampaignRequest.builder() .description("My description") .schedule(schedule) .name("MyCampaign") .segmentId(segmentID) .messageConfiguration(messageConfiguration) .build(); CreateCampaignResponse result = client.createCampaign(CreateCampaignRequest.builder() .applicationId(appID) .writeCampaignRequest(request).build()); System.out.println("Campaign ID: " + result.campaignResponse().id()); return result.campaignResponse(); } catch (PinpointException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return null; } }
-
有关API详细信息,请参阅 “AWS SDK for Java 2.x API参考 CreateCampaign” 中的。
-
- Kotlin
-
- SDK对于 Kotlin 来说
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 suspend fun createPinCampaign( appId: String, segmentIdVal: String, ) { val scheduleOb = Schedule { startTime = "IMMEDIATE" } val defaultMessageOb = Message { action = Action.OpenApp body = "My message body" title = "My message title" } val messageConfigurationOb = MessageConfiguration { defaultMessage = defaultMessageOb } val writeCampaign = WriteCampaignRequest { description = "My description" schedule = scheduleOb name = "MyCampaign" segmentId = segmentIdVal messageConfiguration = messageConfigurationOb } PinpointClient { region = "us-west-2" }.use { pinpoint -> val result: CreateCampaignResponse = pinpoint.createCampaign( CreateCampaignRequest { applicationId = appId writeCampaignRequest = writeCampaign }, ) println("Campaign ID is ${result.campaignResponse?.id}") } }
-
有关API详细信息,请参阅CreateCampaign
中的 Kotlin AWS SDK API 参考。
-
有关 AWS SDK开发者指南和代码示例的完整列表,请参阅将 Amazon Pinpoint 与 AWS SDK。本主题还包括有关入门的信息以及有关先前SDK版本的详细信息。
CreateApp
CreateExportJob