本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
CreateApp
搭配 AWS SDK或 使用 CLI
下列程式碼範例示範如何使用 CreateApp
。
- CLI
-
- AWS CLI
-
範例 1:建立應用程式
以下
create-app
範例會建立新應用程式 (專案)。aws pinpoint create-app \ --create-application-request
Name=ExampleCorp
輸出:
{ "ApplicationResponse": { "Arn": "arn:aws:mobiletargeting:us-west-2:AIDACKCEVSQ6C2EXAMPLE:apps/810c7aab86d42fb2b56c8c966example", "Id": "810c7aab86d42fb2b56c8c966example", "Name": "ExampleCorp", "tags": {} } }
範例 2:建立已標記的應用程式
下列
create-app
範例會建立新的應用程式 (專案),並將標籤 (金鑰和值) 與應用程式產生關聯。aws pinpoint create-app \ --create-application-request Name=ExampleCorp,tags={"Stack"="Test"}
輸出:
{ "ApplicationResponse": { "Arn": "arn:aws:mobiletargeting:us-west-2:AIDACKCEVSQ6C2EXAMPLE:apps/810c7aab86d42fb2b56c8c966example", "Id": "810c7aab86d42fb2b56c8c966example", "Name": "ExampleCorp", "tags": { "Stack": "Test" } } }
-
如需API詳細資訊,請參閱 命令參考 CreateApp
中的 。 AWS CLI
-
- 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.CreateAppRequest; import software.amazon.awssdk.services.pinpoint.model.CreateAppResponse; import software.amazon.awssdk.services.pinpoint.model.CreateApplicationRequest; 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 CreateApp { public static void main(String[] args) { final String usage = """ Usage: <appName> Where: appName - The name of the application to create. """; if (args.length != 1) { System.out.println(usage); System.exit(1); } String appName = args[0]; System.out.println("Creating an application with name: " + appName); PinpointClient pinpoint = PinpointClient.builder() .region(Region.US_EAST_1) .build(); String appID = createApplication(pinpoint, appName); System.out.println("App ID is: " + appID); pinpoint.close(); } public static String createApplication(PinpointClient pinpoint, String appName) { try { CreateApplicationRequest appRequest = CreateApplicationRequest.builder() .name(appName) .build(); CreateAppRequest request = CreateAppRequest.builder() .createApplicationRequest(appRequest) .build(); CreateAppResponse result = pinpoint.createApp(request); return result.applicationResponse().id(); } catch (PinpointException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return ""; } }
-
如需API詳細資訊,請參閱 參考 CreateApp中的 。 AWS SDK for Java 2.x API
-
- Kotlin
-
- SDK 適用於 Kotlin
-
注意
還有更多 。 GitHub尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 suspend fun createApplication(applicationName: String?): String? { val createApplicationRequestOb = CreateApplicationRequest { name = applicationName } PinpointClient { region = "us-west-2" }.use { pinpoint -> val result = pinpoint.createApp( CreateAppRequest { createApplicationRequest = createApplicationRequestOb }, ) return result.applicationResponse?.id } }
-
如需API詳細資訊,請參閱CreateApp
中的 AWS SDK for Kotlin API參考 。
-
如需開發人員指南和程式碼範例的完整清單 AWS SDK,請參閱 搭配 使用 Amazon Pinpoint AWS SDK。本主題也包含有關入門的資訊,以及先前SDK版本的詳細資訊。
動作
CreateCampaign