【问题标题】:Retrieving user attributes(alias, required and custom) in amazon cognito userpool for android在 amazon cognito userpool for android 中检索用户属性(别名、必需和自定义)
【发布时间】:2017-02-22 07:34:34
【问题描述】:

下面的文档显示我们需要使用GetDetailsHandler来获取android的用户属性。

http://docs.aws.amazon.com/cognito/latest/developerguide/tutorial-integrating-user-pools-android.html#tutorial-integrating-user-pools-user-details-android

我已经尝试过了,在 onSuccess() 中,我做到了

GetDetailsHandler getDetailsHandler = new GetDetailsHandler() {
        @Override
        public void onSuccess(CognitoUserDetails cognitoUserDetails) {
        Map userAtts = cognitoUserDetails.getAttributes().getAttributes();
        String userName =       userAtts.get("alias:preferred_username").toString();
        }

        @Override
        public void onFailure(Exception exception) {
       }
    };

用户名仍返回 null。我在 onCreate() 中实现了它。我做错了吗?任何帮助表示赞赏。

【问题讨论】:

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


    【解决方案1】:

    你必须先初始化地图,然后才能使用

    Map userAtts=new HashMap();
    userAtts =cognitoUserDetails.getAttributes().getAttributes();
    String userName = userAtts.get("alias:preferred_username").toString();
    

    有效

    【讨论】:

      【解决方案2】:

      如果您尝试访问标准用户属性“preferred_username”中的值,那么键就是“preferred_username”。
      要访问首选用户名,请尝试以下操作:

      Map userAtts    = cognitoUserDetails.getAttributes().getAttributes();
      String userName = userAtts.get("preferred_username").toString();
      

      【讨论】:

        猜你喜欢
        • 2019-04-16
        • 2020-10-16
        • 1970-01-01
        • 1970-01-01
        • 2014-07-03
        • 1970-01-01
        • 2018-03-25
        • 1970-01-01
        • 2014-04-22
        相关资源
        最近更新 更多