와 CreateCampaign 함께 사용 AWS SDK - Amazon Pinpoint

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

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 내용은 참조CreateCampaign의 섹션을 참조하세요. AWS SDK for Java 2.x API

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의 에서 AWS SDK Kotlin API 참조 를 참조하세요.

개발자 안내서 및 코드 예제의 AWS SDK 전체 목록은 섹션을 참조하세요에서 Amazon Pinpoint 사용 AWS SDK. 이 주제에는 시작하기에 대한 정보와 이전 SDK 버전에 대한 세부 정보도 포함되어 있습니다.