0

AWS Cognito Unity SDKを使用してFacebookログインでユーザーを認証します。AWS Cognitoを使用してFacebook Idで認証する方法は?

これは私のコードです:

void Start() 

{ 
    InitCognito(); 

} 
public void InitCognito() 
{ 
    UnityInitializer.AttachToGameObject (this.gameObject); 
    credentials = new CognitoAWSCredentials (
     identity_pool_id, // Identity Pool ID 
     region // Region 
    ); 

    Debug.Log ("identity_pool_id = " + identity_pool_id + " region = " + region); 

    credentials.GetIdentityIdAsync(delegate(AmazonCognitoIdentityResult<string> 
     result) { 
     if (result.Exception != null) { 
      Debug.LogError(result.Exception.ToString()); 
     } 
     string identityId = result.Response; 
     Debug.Log("identityId = "+identityId); 
     FBInit(); 
    }); 



} 



public void FBInit() 
{ 
    FB.Init(this.OnInitComplete, this.OnHideUnity); 
    Debug.Log("FB.Init() called with " + FB.AppId); 

} 

public void FBLogin() 
{ 

    FB.LogInWithReadPermissions(new List<string>() { "public_profile", "email", "user_friends" }, this.HandleResult); 

} 


private void OnInitComplete() 
{ 
    Debug.Log("Success - Check log for details"); 
    Debug.Log("Success Response: OnInitComplete Called\n"); 
    Debug.Log(string.Format(
     "OnInitCompleteCalled IsLoggedIn='{0}' IsInitialized='{1}'", 
     FB.IsLoggedIn, 
     FB.IsInitialized)); 

    if (AccessToken.CurrentAccessToken != null) 
    { 
     Debug.Log("Access token = "+AccessToken.CurrentAccessToken.ToString()); 
    } 
    FBLogin(); 
} 

private void OnHideUnity(bool isGameShown) 
{ 
    Debug.Log("Success - Check log for details"); 
    Debug.Log(string.Format("Success Response: OnHideUnity Called {0}\n", isGameShown)); 
    Debug.Log("Is game shown: " + isGameShown); 
} 
protected void HandleResult(IResult result) 
{ 
    if (result == null) 
    { 
     Debug.Log("Null Response\n"); 

     return; 
    } 



    // Some platforms return the empty string instead of null. 
    if (!string.IsNullOrEmpty(result.Error)) 
    { 
     Debug.Log("Error - Check log for details"); 
     Debug.Log("Error Response:\n" + result.Error); 
    } 
    else if (result.Cancelled) 
    { 
     Debug.Log ("Cancelled - Check log for details"); 
     Debug.Log("Cancelled Response:\n" + result.RawResult); 
    } 
    else if (!string.IsNullOrEmpty(result.RawResult)) 
    { 
     Debug.Log ("Success - Check log for details"); 
     Debug.Log ("Success Response:\n" + result.RawResult); 
     Debug.Log ("Access Token = "+AccessToken.CurrentAccessToken); 
     Debug.Log ("Access Token = "+AccessToken.CurrentAccessToken.TokenString); 
     Debug.Log ("Access User Id =" + AccessToken.CurrentAccessToken.UserId); 
     credentials.AddLogin ("graph.facebook.com", AccessToken.CurrentAccessToken.TokenString); 
     if (credentials.CurrentLoginProviders.Length > 0) { 
      Debug.Log (credentials.CurrentLoginProviders[0]); 
     } 

     Debug.Log (credentials.GetCachedIdentityId()); 
    } 
    else 
    { 
     Debug.Log ("Empty Response\n"); 
    } 


} 

InitCognito()メソッドが実行されると(私は同じデバイス上でこのアプリを再インストールしたら、不正アイデンティティ同上の変更)を、私は不正なアイデンティティIDを取得します。その後、私はFacebookのユーザーIDとトークンを正常に取得できます。

Cognitoデベロッパーガイドに続いて、credentials.AddLogin()を使用してFacebookのログイン情報を追加します。しかし、このメソッドが実行された後、Debug.Log (credentials.GetCachedIdentityId())は、アイデンティティIDがunidentified Identity IDと同じであることを示しています。これは、Facebook Idを参照する特定のIDではなく、AWS Cognitoコンソールには「Linked Login」がないことが示されます。 credentials.AddLogin()を間違った方法で使用しますか?

ありがとうございます!

答えて

0

ログイントークンを設定しても、SDKがサーバーに送信しているとは限りません。あなたはそれを強制する必要があります下記のコマンドを実行しようとすることはできますか?私はあなたが同じアイデンティティを見ている理由は、それがサーバーを変更に更新していないことを推測しています。これはCognito developer guideから引き出されています。

credentials.GetIdentityIdAsync(delegate(AmazonCognitoIdentityResult<string> result) { 
    if (result.Exception != null) { 
     //Exception! 
    } 
    string identityId = result.Response; 
}); 
関連する問題