【问题标题】:Call ListUsers (amazon cognito) in Android Java在 Android Java 中调用 ListUsers (amazon cognito)
【发布时间】:2022-01-11 12:39:24
【问题描述】:

如何从 Android Studo (java) 准确调用 ListUsers ? :https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_ListUsers.html#API_ListUsers_RequestSyntax

我正在使用以下代码进行初始化,我也可以调用我的 REST api。

 try {
            // Add these lines to add the `AWSApiPlugin` and `AWSCognitoAuthPlugin`
            Amplify.addPlugin(new AWSApiPlugin());
            Amplify.addPlugin(new AWSCognitoAuthPlugin());
            Amplify.configure(GlobalApplication.getAppContext());

            Log.i("MyAmplifyApp", "Initialized Amplify.");
        } catch (AmplifyException error) {
            Log.e("MyAmplifyApp", "Could not initialize Amplify.", error);

            
        }

我的目标是检索我所有的 cognito 用户池用户名

【问题讨论】:

    标签: java android amazon-web-services amazon-cognito


    【解决方案1】:

    我创建了一个 lambda 函数来为我做同样的事情:

     app.get(path + "/users", function(req, res) {
    
      
      const cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider()
      var params = {
        UserPoolId: "eu-west-1_..........", 
        Limit: '10',
      };
      cognitoidentityserviceprovider.listUsers(params, function(err, data) {
        if (err) {
          return res.status(500).json(err)
        }
        res.json({users: data.Users});
      });
    });
    

    【讨论】:

      【解决方案2】:

      要构建可以调用 AWS 服务的 Android 原生应用,请使用新的 AWS SDK for Kotlin。这是一个新教程,向您展示如何使用 Android Studio 构建调用 Amazon DynamoDB 和 SNS 的 Android 应用程序。它将向您展示如何启动和运行:

      Creating your first Native Android application using the AWS SDK for Kotlin

      因为您想在应用中使用 Cognito,请参阅 Cognito Kotlin 示例:

      https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/kotlin/services/cognito/src/main/kotlin/com/kotlin/cognito

      因此,只需按照上述教程在 Android Studio 中创建一个 Android 应用程序,将 DynamoDB 和 SNS 替换为 Cognito 并构建您的 Native Android 应用程序。

      要了解有关适用于 Kotlin 的 AWS 开发工具包的更多信息,请参阅开发指南:

      Get started with the SDK for Kotlin

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-05-12
        • 2021-02-12
        • 2017-10-02
        • 2019-04-26
        • 2019-03-23
        • 2016-09-11
        • 2018-03-03
        • 1970-01-01
        相关资源
        最近更新 更多