- Home /
Displaying profile pictures in all connected devices
Basically I am working on multiplayer Tic Tac Toe game. I have added face book connectivity to play with friends. Now I want to display profile picture on screen to each connected player.
Now I am stuck at how to display two connected players picture on each device? Means I can able to see my friends picture on my device screen to whom I am playing. So how to manage this condition? Whether I have to use any web service for this or not?
Please give some suggestions in this?
Answer by fafase · Feb 27, 2015 at 06:34 AM
Facebook picture is just a url and is not even private data. What you need is the user id from your friend that you pass to this url:
https://graph.facebook.com/userIDHere/?fields=picture&type=large
this url will return a json file:
{
"picture": {
"data": {
"is_silhouette": false,
"url": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xap1/v/hereIsmypersonalValue"
}
},
"id": "783658663"
}
then using a json parser you get the url value and download via a basic WWW call.
WWW www new WWW(url);
Texture2D texture = www.texture;
@fafase, Thanks for your reply. Sorry but I am really weak in understanding facebook graph api. If you suggest me any blog or tutorial that guide me on same topic then it is better for me and I have to ask less question here.
Basically what I have understand using above code is!!!!
After facebook authentication, I have to call following statement
string url = "https://graph.facebook.com/userIDHere/?fields=picture&type=large";
WWW www new WWW(url);
Texture2D texture = www.texture;
Am I right in this?
When the user agrees to log in to facebook, you are able to retrieve information, this is when the API asks "Do you allow the app to access your USERID, FRIEND LIST..." here you list what you need.
In your case, you want the friend list with userID (I think the user id always comes along). You cannot rely on friend's name since you may get duplicate.
The file you receive is a json so you can parse it easily and retrieve the user id from it. Then you place it in the url to get the picture. (Can't find any friend list example...)
string url = "https://graph.facebook.com/"+userID+" /?fields=picture&type=large";
WWW www = new WWW(url);
yield return www;
string json = www.text;
Now json is:
{
"picture": {
"data": {
"is_silhouette": false,
"url": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xpf1/v/t1.0-1/c14.4.153.153/s50x50/1939620_10101266232851011_437577509_n.jpg?oh=c44bd203c2f72072de3ded44edd619b9&oe=5584066C&__gda__=1431020283_bb25bd350817f061ba62af51b2b92941"
}
},
"id": "4"
}
string picUrl = json["picture"]["data"]["url"]; // this line depends on the parser you use
WWW www = new WWW(picUrl);
yield return www;
Texture2D pic = www.texture;
@fafase, Okay I got some what my $$anonymous$$d clear by your last comment. Some more questions,
In above url, I have to use facebook userid in place of mark.zuckerberg as per your suggestion. Am I right in this?
You have give me this question to retrieve picture information if I want some other information the what is the url for that? Where I get information related to that?
Yes you change that name part.
For the info you are after, it depends on what you want, only the picture, name and userID are public info, the rest needs to be accepted (friend list, likes and so on).
Here is the API page of data you can access https://developers.facebook.com/docs/graph-api/reference
From what I recall, when you ask the user for permission, you list what you want from it, the user agrees or not. If he does, Facebook will send a json file containing all the info you asked from the user. That is the one you need to parse to get the info you want. That is why you cannot just place the url above in google and get a result since it is a url that required authorization as opposed to the picture url that display the picture on screen since it is a public information (you cannot set your profile picture, name and userID as private in Facebook settings but you can set all the rest, pictures, friend list, status, comments and so on).
Your answer
Follow this Question
Related Questions
Facebook Profile pic Callback don't Execute 0 Answers
can i use facebook Graph api for ios? 0 Answers
Play game with FB friends 1 Answer
Facebook Friend Pictures Returning Blank on Leaderboard 0 Answers
facebook profile pic not working 0 Answers