GetEndpoint 搭配 a AWS SDK 或 CLI 使用 - AWS SDK 程式碼範例

文件 AWS SDK AWS 範例 SDK 儲存庫中有更多可用的 GitHub 範例。

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

GetEndpoint 搭配 a AWS SDK 或 CLI 使用

下列程式碼範例示範如何使用 GetEndpoint

CLI
AWS CLI

如要擷取應用程式之特定端點的設定和屬性相關資訊

下列 get-endpoint 範例會擷取應用程式之特定端點的設定和屬性相關資訊。

aws pinpoint get-endpoint \ --application-id 611e3e3cdd47474c9c1399a505665b91 \ --endpoint-id testendpoint \ --region us-east-1

輸出:

{ "EndpointResponse": { "Address": "+11234567890", "ApplicationId": "611e3e3cdd47474c9c1399a505665b91", "Attributes": {}, "ChannelType": "SMS", "CohortId": "63", "CreationDate": "2019-01-28T23:55:11.534Z", "EffectiveDate": "2021-08-06T00:04:51.763Z", "EndpointStatus": "ACTIVE", "Id": "testendpoint", "Location": { "Country": "USA" }, "Metrics": { "SmsDelivered": 1.0 }, "OptOut": "ALL", "RequestId": "a204b1f2-7e26-48a7-9c80-b49a2143489d", "User": { "UserAttributes": { "Age": [ "24" ] }, "UserId": "testuser" } } }
  • 如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 GetEndpoint

Java
Java 2.x 的 SDK
注意

還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

import com.google.gson.FieldNamingPolicy; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.pinpoint.PinpointClient; import software.amazon.awssdk.services.pinpoint.model.EndpointResponse; import software.amazon.awssdk.services.pinpoint.model.GetEndpointResponse; import software.amazon.awssdk.services.pinpoint.model.PinpointException; import software.amazon.awssdk.services.pinpoint.model.GetEndpointRequest; /** * 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 LookUpEndpoint { public static void main(String[] args) { final String usage = """ Usage: <appId> <endpoint> Where: appId - The ID of the application to delete. endpoint - The ID of the endpoint.\s """; if (args.length != 2) { System.out.println(usage); System.exit(1); } String appId = args[0]; String endpoint = args[1]; System.out.println("Looking up an endpoint point with ID: " + endpoint); PinpointClient pinpoint = PinpointClient.builder() .region(Region.US_EAST_1) .build(); lookupPinpointEndpoint(pinpoint, appId, endpoint); pinpoint.close(); } public static void lookupPinpointEndpoint(PinpointClient pinpoint, String appId, String endpoint) { try { GetEndpointRequest appRequest = GetEndpointRequest.builder() .applicationId(appId) .endpointId(endpoint) .build(); GetEndpointResponse result = pinpoint.getEndpoint(appRequest); EndpointResponse endResponse = result.endpointResponse(); // Uses the Google Gson library to pretty print the endpoint JSON. Gson gson = new GsonBuilder() .setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE) .setPrettyPrinting() .create(); String endpointJson = gson.toJson(endResponse); System.out.println(endpointJson); } catch (PinpointException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } System.out.println("Done"); } }
  • 如需 API 詳細資訊,請參閱 GetEndpoint AWS SDK for Java 2.x 參考中的 API

Kotlin
Kotlin 的 SDK
注意

還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

suspend fun lookupPinpointEndpoint( appId: String?, endpoint: String?, ) { PinpointClient { region = "us-west-2" }.use { pinpoint -> val result = pinpoint.getEndpoint( GetEndpointRequest { applicationId = appId endpointId = endpoint }, ) val endResponse = result.endpointResponse // Uses the Google Gson library to pretty print the endpoint JSON. val gson: com.google.gson.Gson = GsonBuilder() .setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE) .setPrettyPrinting() .create() val endpointJson: String = gson.toJson(endResponse) println(endpointJson) } }
  • 如需 API 詳細資訊,請參閱 GetEndpoint AWS for Kotlin SDK 參考中的 API