2017-10-27 16 views
0

これまでは、 "identityManager.getUserName"を実行して、認証されたアプリケーションユーザーのuserNameを取得できました。しかし、今これは、更新されたアンドロイドSDK "mysampleapp"のケースではありません。CognitoUserをインスタンス化してandroid sdkでユーザー属性を取得する方法

私はAWSのチュートリアルで見つかった次のコードでuserName属性を取得しようとしていますが、私はエラーを取得しています:

// Implement callback handler for getting details 
GetDetailsHandler getDetailsHandler = new GetDetailsHandler() { 
@Override 
public void onSuccess(CognitoUserDetails cognitoUserDetails) { 
    // The user detail are in cognitoUserDetails 
    Map userAtts = new HashMap(); 
    userAtts = cognitoUserDetails.getAttributes().getAttributes(); 
    String userName = userAtts.get("given_name").toString(); 
} 

@Override 
public void onFailure(Exception exception) { 
    // Getting the error here 
} 
}; 

// Fetch the user details 
cognitoUser.getDetailsInBackground(getDetailsHandler); 

私の質問は、私は上記のコードでは、「cognitouser」変数をインスタンス化はどうすればよいのですか?

私は以下を試みましたが、うまくいかなかった。

CognitoUserPool userPool = new CognitoUserPool(this, userPool, keyID, 
    keySecrete); 
    CognitoUser cognitoUser = userPool.getCurrentUser(); 

私はエラーを取得する:

onFailure==com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoNotAuthorizedException:User-ID is null 

私は自分のユーザー名を取得しようとする前に、ユーザーがすでに認証されたユーザーとしてログインしている「無アイデンティティエラー」私を与えません。 ご意見をお寄せください。私はちょうど "コグニター"をinstanciateする必要があり、私の仕事を得る。

答えて

0

推奨されていないCognitoUserPoolクラスのコンストラクタを使用していないことを確認してください。これは私のために働いた:

CognitoUserPool userPool = new CognitoUserPool(this, awsConfiguration); 
関連する問題