question

c-ming2004 avatar image
c-ming2004 asked

How to transfer data from device A to device B via linked facebook

Halo, I am using Unity and Playfab. I want to do recovery from linked facebook account.

In my case,

device A > create account A > linked facebook A

device B > create account B > linked facebook A (it will unlink device A automatically)

***Above actions are good for me. ***

******And I don't know how to do the below step.******

account B get all data [Player Data (Title)] from account A > unlink the customID(device A) from account A

The result I want:

1) account B will get all data from account A

2) account A will never be login by any devices. No one can login it anymore.

3) device A > create account C (This action is also fine for me)

Does anyone provide me the code for result 1,2? Thanks a lot!!

 public void FBlogin(){
        List<string> permessions = new List<string>();
        permessions.Add("public_profile");
        FB.LogInWithReadPermissions(permessions,AuthCallResult);
    }

    void AuthCallResult(ILoginResult result){
        if(result.Error != null){
            Debug.Log(result.Error);
        }else{
            if(FB.IsLoggedIn){
                Debug.Log("FB logged in");
                var aToken = Facebook.Unity.AccessToken.CurrentAccessToken;
                var request = new LinkFacebookAccountRequest {
                    AccessToken = aToken.TokenString,
                    ForceLink = true} ;
                PlayFabClientAPI.LinkFacebookAccount(request,OnSuccess,OnError);
            }
            else{
                Debug.Log("login failed");
            }
        }
    }

    void OnSuccess(LinkFacebookAccountResult result){
        Debug.Log("linked fb Successfully!");
        GetAppearance();
    }

    void OnError(PlayFabError Error){
        Debug.Log("Error while lniked fb");
        Debug.Log(Error.GenerateErrorReport());
    }

    public void GetAppearance(){
        PlayFabClientAPI.GetUserData(new GetUserDataRequest(), OnDataRecieved, OnError);
    } 


    void OnDataRecieved(GetUserDataResult result){
        Debug.Log("recieved user data");
        if(result.Data != null && result.Data.ContainsKey("Level")){
            leveltext.text = "Level: " + (result.Data["Level"].Value);
            //convert string to int
            level = int.Parse(result.Data["Level"].Value);
        }else{
            Debug.Log("data not completed!");
        }
    }


10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Seth Du avatar image
Seth Du answered

>>"get all data from account A"

May I ask does it mean "Player Data"(internal and read-only), or simply all the data, including inventory, Entity Objects, etc.?

8 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

c-ming2004 avatar image c-ming2004 commented ·

I mean all data includes Display name, inventory, etc.

0 Likes 0 ·
Seth Du avatar image Seth Du ♦ c-ming2004 commented ·

Actually, you may not need to transfer. Even though Game Manager and API can only get the latest linked login identity, players can actually link multiple identities from the same platform, which means you can link Device B to Account A.

  • device A > create account A > linked facebook A
  • Login Facebook A in Device B, link Device B.

In this scenario, both device B and device A can access account A. Facebook login is recoverable. If you have concerns about device A ID, you may --

  1. Log into Account A with Facebook A on Device B
  2. Check all the login identities and remove Device A
  3. Link Device B.
0 Likes 0 ·
c-ming2004 avatar image c-ming2004 Seth Du ♦ commented ·

What if device A and device B login at the same time?

May I have the code of "Login Facebook A in Device B, link Device B"?

I had tried like below but it does not link Device B.

public void FacecBooklogin(){
            List<string> permessions = new List<string>();
            permessions.Add("public_profile");
            FB.LogInWithReadPermissions(permessions,OnFacebookLoggedIn);
        }
        void OnFacebookLoggedIn(ILoginResult result){
            if(result.Error != null){
                Debug.Log(result.Error);
            }else{
                if(FB.IsLoggedIn){
                    Debug.Log("FB logged in");
                    PlayFabClientAPI.LoginWithFacebook(new LoginWithFacebookRequest { CreateAccount = true, AccessToken = AccessToken.CurrentAccessToken.TokenString},
                    OnPlayfabFacebookAuthComplete, OnPlayfabFacebookAuthFailed);
                }else{
                    Debug.Log("login failed");
                }
            }
        }

   void OnPlayfabFacebookAuthComplete(LoginResult result)
    {
    }
    void OnPlayfabFacebookAuthFailed(PlayFabError error)
    {
    }


0 Likes 0 ·
Show more comments
Show more comments

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.