sending profile picture over photon

i'm working on a small multiplayer game using photon. i get the player's profile picture from gamecenter, and i'd like to show that picture to the opponent too. is there an easy way to send this picture over photon?

i have read something about serializing the image as a base64 string, can someone kindly shed some light on how to do that? appreciate it. :geek:

Comments

  • Why serialize it as string? You could send byte[].
    Better yet: Can't you send the profile ID and then load the image from GameCenter instead of sending it via Photon? Then it won't interact with the game synchronization and actually, Photon is not built to send images around...
  • thanks tobias. you're absolutely right, i wasn't aware that i could load someone else's profile image from gamecenter. that is a significantly better solution indeed. thanks!
  • Hey Tobias ? I just getting pic from facebook . but tell me how it synchronize on rpc to other friends ?
  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @Arham,

    Thank you for choosing Photon!

    This is not a good practice.
    What you should do instead is get the profile picture URL using Facebook Unity SDK and then download it on each client.
    Photon may help you only discover or guess other players' Facebook ID which should be set to Photon's UserID.
  • hi @JohnTube
    Thanks for the reply .
    But I still confused . As I am getting the picture and it shown on photonview.ismine but not when photonview.ismine == false ;
  • JohnTube
    JohnTube ✭✭✭✭✭
    edited January 2018
    Hi @Arham,

    Here is how Photon and Facebook should work together:

    - Use Facebook authentication with Photon. This way players can connect using their Facebook account and be identified on every session because the Photon UserID will be set to the Facebook ID.
    - Because Facebook ID is the same as the Photon UserID, given your Facebook friends' IDs you can tell if they are offline or online and if online which room they are joined to if any.
    - Invite Facebook friends to a Photon room by sending them the room name using Facebook.
    - In a room, you can query other players' Facebook information (including the profile picture) even if they are not your friends. This is possible also because of the fact that Photon UserID is set to the Facebook ID.


    As I am getting the picture and it shown on photonview.ismine but not when photonview.ismine == false
    You are probably using the wrong Facebook API request. Getting your own (current logged in Facebook user) profile picture URL is different than getting a profile picture URL of another user.
    You can find more information here.
  • JohnTube
    JohnTube ✭✭✭✭✭
    edited January 2018
    "Do you haz teh codez?"

    yes, why not, something like:
    
    private void LoadFacebookProfilePictureAsync()
        if (photonView.isMine)
        {
            FB.API("/me/picture?redirect=false&width=" + width + "&height=" + height, HttpMethod.GET, ProfilePhotoCallback);
        }
        else 
        {
           FB.API ("/" + photonView.owner.UserId + "/picture?redirect=false&width=" + width + "&height=" + height, HttpMethod.GET, ProfilePhotoCallback);
        }
    }
    
    
    private void ProfilePhotoCallback (IGraphResult result)
    {
            if (string.IsNullOrEmpty(result.Error) && !result.Cancelled) 
            {
                IDictionary data = result.ResultDictionary["data"] as IDictionary;
                string photoURL = data["url"] as string;
                StartCoroutine(DownloadPicture(photoURL));
            }
    }
    
    private IEnumerator DownloadPicture(string url) 
    {
            WWW www = new WWW(url); // replace with new UnityWebRequest
            yield return www;
            this.profilePic = www.texture;
    
            //Create a new sprite using the Texture2D from the url. 
            //Adjust accordingly
    
            image.overrideSprite = Sprite.Create(www.texture, new Rect(0, 0, width, height), Vector2.zero);  
    }
    sources:
    Facebook Graph API Reference for User Picture
    stackoverflow answer
  • @JohnTube what is userid in fb.api ? what should i pass in userid ?
  • JohnTube
    JohnTube ✭✭✭✭✭
    edited January 2018
    Hi @Arham,

    Please follow our Facebook Authentication Tutorial.

    Facebook ID: AccessToken.CurrentAccessToken.UserId; (for local player available only after successful facebook login)
    Photon User ID: PhotonNetwork.player.UserId (for local player) and otherPlayer.UserId (for any remote player)

    After successful facebook authentication, both values should match.

    EDIT: I have updated the code snippet above.
    The userId should could be photonView.owner.UserId.
  • Hey @JohnTube

    Thankyou so much man . Thankyou for your support . It means alot . Your answer is 100% correct .