sending profile picture over photon

The whole answer can be found below.

Please note: The Photon forum is closed permanently. After many dedicated years of service we have made the decision to retire our forum and switch to read-only: we've saved the best to last! And we offer you support through these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

sending profile picture over photon

hamletarcher
2013-06-28 06:22:35

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

Tobias
2013-06-28 10:14:05

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...

hamletarcher
2013-06-28 11:39:56

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!

Arham
2018-01-02 08:08:21

Hey Tobias ? I just getting pic from facebook . but tell me how it synchronize on rpc to other friends ?

JohnTube
2018-01-02 11:18:54

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.

Arham
2018-01-02 11:25:08

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
2018-01-02 13:25:40

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
2018-01-03 11:39:35

"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

Arham
2018-01-07 22:34:06

@JohnTube what is userid in fb.api ? what should i pass in userid ?

JohnTube
2018-01-08 11:40:50

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.

Arham
2018-01-11 22:09:13

Hey @JohnTube

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

Back to top