CelebrityInfo.java - AWS Code Sample


CelebrityInfo.java demonstrates how to get information about a detected celebrity.

/** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * * This file is licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. A copy of * the License is located at * * http://aws.amazon.com/apache2.0/ * * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. */ package com.example.rekognition; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.rekognition.RekognitionClient; import software.amazon.awssdk.services.rekognition.model.GetCelebrityInfoRequest; import software.amazon.awssdk.services.rekognition.model.GetCelebrityInfoResponse; import software.amazon.awssdk.services.rekognition.model.RekognitionException; public class CelebrityInfo { public static void main(String[] args) { final String USAGE = "\n" + "CelebrityInfo - how to get information about a detected celebrity\n\n" + "Usage: CelebrityInfo <id>\n\n" + "Where:\n" + "id - the ID value of the celebrity; you can use the RecognizeCelebrities example to get the ID value \n\n"; if (args.length < 1) { System.out.println(USAGE); System.exit(1); } String id = args[0]; Region region = Region.US_EAST_2; RekognitionClient rekClient = RekognitionClient.builder() .region(region) .build(); // Get celebrity information getCelebrityInfo(rekClient, id); } public static void getCelebrityInfo(RekognitionClient rekClient, String id ) { try { GetCelebrityInfoRequest info = GetCelebrityInfoRequest.builder() .id(id) .build(); GetCelebrityInfoResponse response = rekClient.getCelebrityInfo(info); //Display celebrity information System.out.println("celebrity name: " + response.name()); System.out.println("Further information (if available):"); for (String url: response.urls()){ System.out.println(url); } } catch (RekognitionException e) { System.out.println(e.getMessage()); System.exit(1); } } }

Sample Details

Service: Amazon Rekognition

Last tested: 6-10-2020

Author: scmacdon - AWS

Type: full-example