你知道,我已經使用了COgnito,但是從來不需要通過子查詢(或者除了用戶名之外的其他參數)查找。我研究它,因爲你可以,但它不是很清楚(就像他們的許多文檔)。這是我看到你可以嘗試...希望它可以幫助男人。
// the imported ListUsersResult is...
import com.amazonaws.services.cognitoidp.model.ListUsersRequest;
import com.amazonaws.services.cognitoidp.model.ListUsersResult;
// class var
protected final AWSCognitoIdentityProviderClient identityUserPoolProviderClient;
// omitted stuff...
// initialize the Cognito Provider client. This is used to talk to the user pool
identityUserPoolProviderClient = new AWSCognitoIdentityProviderClient(new BasicAWSCredentials(AWS_ACCESS_KEY, AWS_SECRET_KEY)); // creds are loaded via variables that are supplied to my program dynamically
identityUserPoolProviderClient.setRegion(RegionUtils.getRegion(USER_POOL_REGION)); // var loaded
// ...some code omitted
ListUsersRequest listUsersRequest = new ListUsersRequest();
listUsersRequest.withUserPoolId(USER_POOL_ID); // id of the userpool, look this up in Cognito console
listUsersRequest.withFilter("sub=xyz"); // i THINK this is how the Filter works... the documentation is terribad
// get the results
ListUsersResult result = identityUserPoolProviderClient.listUsers(listUsersRequest);
List<UserType> userTypeList = result.getUsers();
// loop through them
for (UserType userType : userTypeList) {
List<AttributeType> attributeList = userType.getAttributes();
for (AttributeType attribute : attributeList) {
String attName = attribute.getName();
String attValue = attribute.getValue();
System.out.println(attName + ": " + attValue);
}
}
如果你的用戶名,你可以得到這樣
// build the request
AdminGetUserRequest idRequest = new AdminGetUserRequest();
idRequest.withUserPoolId(USER_POOL_ID);
idRequest.withUsername(username);
// call cognito for the result
AdminGetUserResult result = identityUserPoolProviderClient.adminGetUser(idRequest);
// loop through results
用戶非常感謝你對這個答案,似乎很樂於助人,在與他們的文檔線。奇怪的是,雖然我成功地導入了ListUsersRequest庫,但是我的eclipse告訴我.withFilter不是ListUsersRequest類的廢話方法。我有困惑我正在使用正確的ListUsersRequest類,並從正確的地方導入它,任何想法,爲什麼它不會工作? – HelloCoding
另外我想知道在這段代碼中identityUserPoolProviderClient是什麼類?我檢查了AmazonCognitoIdentityClient類的文檔,但它沒有方法listUsers,所以我不認爲是這樣。 – HelloCoding
嘿,很高興幫助。這裏是一些更多的信息添加到答案... – Matt