尝试使用Cognito(在Android应用中)获取托管在s3上的文件,如下所示:

....
         AmazonS3 s3 = new AmazonS3Client(getCredentials(MyActivity.this));
         S3Object object = s3.getObject(new GetObjectRequest("mybucket", "myfile"));
....

public static CognitoCachingCredentialsProvider  getCredentials(Context ctx)
    {
        CognitoCachingCredentialsProvider cognitoProvider = new CognitoCachingCredentialsProvider(
                ctx,
                "us-east-1:xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx", /* Identity Pool ID */
                Regions.US_EAST_1 /* Region */
            );
        return cognitoProvider;
    }


显示此错误:

Unable to execute HTTP request: Unable to resolve host "cognito-identity.us-east-1.amazonaws.com": No address associated with hostname
: I/AmazonHttpClient(3427): java.net.UnknownHostException: Unable to resolve host "cognito-identity.us-east-1.amazonaws.com": No address associated with hostname
: I/AmazonHttpClient(3427):     at java.net.InetAddress.lookupHostByName(InetAddress.java:400)
: I/AmazonHttpClient(3427):     at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)


有什么问题吗?

最佳答案

您可能忘记了包含以下权限:

<uses-permission android:name="android.permission.INTERNET" />


有关更多详细信息,请参见Set Up the SDK for Android

08-07 22:37