为什么我的亚马逊识别程序会引发此错误?

时间:2019-03-12 03:06:51

标签: java amazon-web-services

按照教程进行,完全按照视频中的步骤进行操作,有人可以看到问题所在吗?希望弄清楚这是一个非常有趣的概念。我认为这与识别客户/位置有关,但这是我的第一个aws项目,因此对我来说有很多未知领域。

感谢您的帮助!

出现此错误:

com.amazonaws.services.rekognition.model.AmazonRekognitionException: The security token included in the request is invalid. (Service: AmazonRekognition; Status Code: 400; Error Code: UnrecognizedClientException; Request ID: 678e90e3-4466-11e9-8116-e94cae3aa352)
        at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1712)
        at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1367)
        at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1113)
        at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:770)
        at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:744)
        at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:726)
        at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:686)
        at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:668)
        at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:532)
        at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:512)
        at com.amazonaws.services.rekognition.AmazonRekognitionClient.doInvoke(AmazonRekognitionClient.java:3430)
        at com.amazonaws.services.rekognition.AmazonRekognitionClient.invoke(AmazonRekognitionClient.java:3397)
        at com.amazonaws.services.rekognition.AmazonRekognitionClient.invoke(AmazonRekognitionClient.java:3386)
        at com.amazonaws.services.rekognition.AmazonRekognitionClient.executeDetectLabels(AmazonRekognitionClient.java:1168)
        at com.amazonaws.services.rekognition.AmazonRekognitionClient.detectLabels(AmazonRekognitionClient.java:1140)
        at com.amazonaws.samples.DetectLabels.main(DetectLabels.java:35)

这是我尝试过的代码

    package com.amazonaws.samples;

    //Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
    //PDX-License-Identifier: MIT-0 (For details, see https://github.com/awsdocs/amazon-rekognition-developer-guide/blob/master/LICENSE-SAMPLECODE.)

    //package com.amazonaws.samples;
    import com.amazonaws.services.rekognition.AmazonRekognition;
    import com.amazonaws.services.rekognition.AmazonRekognitionClientBuilder;
    import com.amazonaws.services.rekognition.model.AmazonRekognitionException;
    import com.amazonaws.services.rekognition.model.DetectLabelsRequest;
    import com.amazonaws.services.rekognition.model.DetectLabelsResult;
    import com.amazonaws.services.rekognition.model.Image;
    import com.amazonaws.services.rekognition.model.Label;
    import com.amazonaws.services.rekognition.model.S3Object;
    import java.util.List;

    public class DetectLabels {

     public static void main(String[] args) throws Exception {

        String photo = "19756622_10211667570038052_5508425252837325962_n.jpg";
        String bucket = "211proj";


        AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.standard().withRegion("us-west-2").build();

        DetectLabelsRequest request = new DetectLabelsRequest()
             .withImage(new Image()
             .withS3Object(new S3Object()
             .withName(photo).withBucket(bucket)))
             .withMaxLabels(10)
             .withMinConfidence(75F);

        try {
           DetectLabelsResult result = rekognitionClient.detectLabels(request);
           List <Label> labels = result.getLabels();

           System.out.println("Detected labels for " + photo);
           for (Label label: labels) {
              System.out.println(label.getName() + ": " + label.getConfidence().toString());
           }
        } catch(AmazonRekognitionException e) {
           e.printStackTrace();
        }
     }
    }

0 个答案:

没有答案