- Home /
Unity Facebook SDK
Hi,
I am trying to use the Facebook SDK for Unity to get people from my friends list and display their names/profile pictures. I have followed through the FriendSmash tutorials and stuff on the Unity page, and downloaded the FriendSmash project (which wouldn't even log me in properly sadly) but it is still not working.
I am trying to use the following code from the tutorial:
void OnLoggedIn()
{
Util.Log("Logged in. ID: " + FB.UserId);
// Reqest player info and profile picture
FB.API("/me?fields=id,first_name,friends.limit(100).fields(first_name,id)", Facebook.HttpMethod.GET, APICallback);
LoadPicture(Util.GetPictureURL("me", 128, 128),MyPictureCallback);
}
void APICallback(FBResult result)
{
Util.Log("APICallback");
if (result.Error != null)
{
Util.LogError(result.Error);
// Let's just try again
FB.API("/me?fields=id,first_name,friends.limit(100).fields(first_name,id)", Facebook.HttpMethod.GET, APICallback);
return;
}
profile = Util.DeserializeJSONProfile(result.Text);
GameStateManager.Username = profile["first_name"];
friends = Util.DeserializeJSONFriends(result.Text);
}
I have debug messages at every line after the result.Error braces, and the code doesn't seem to hit the line after:
profile = Util.DeserializeJSONProfile(result.Text);
although it DOES get through that function. (Debug logs at the beginning and just before it returns both are output in logcat).
The profile/friends variables are remaining null after I am setting them.
Has anybody used this API and had these problems before?
Unity version is 4.5.2 and Facebook SDK is 5.1
EDIT: Forgot to add, after the above code, I can get my profile picture, but not my name or friends or anything like that (anything useful)
Thanks, Sosp
can you show us this part of code? :
FB.Login(Permissions, LoginCallback);
FB.Login("email,publish_actions", LoginCallback);
The app itself on Facebook has the following permissions:
Your public profile
Your friend list
Your email address
EDIT: Does that call only get friends that have already logged in to the app? Or will it return all friends?
Answer by smallbit · Jul 31, 2014 at 01:31 AM
Since some time, facebook will return only friends who logged into app, sorry. You can create several test users (on creation add app permissions already) in the dashboards (roles/test users), add other test users as friends, and than when you launch your app in unity instead of your token use token of one of the test users (from dashboard) , you will be able to retrieve data of their friends (other test users).
Thank you, this has got it working again now :)
Sorry to ask another question, but do you know if it is possible to test Open Graph functionality such as posting scores while the app is not live? Or does the app have to be set to live for these to work?
Thanks again, Sosp
I am afraid you need to turn app live (but it's no hassle at all) just type email and ready. I was able to save and retrieve my score, didn't test friend though because I move to another solution where it comes to storing score (backend).
I have made it live, and managed to Post my score and then Get my score again using the HTTP requests, but nothing is showing in my Activity Log for the Test User(s).
I can make do right now with just storing/retrieving the scores, but it would obviously be preferable to be able to "brag" about the scores to your friends etc.
Thanks, Sosp
EDIT (August 1st 2014) - Okay, so I did some more looking into it, and it seems as though it is only saving locally on this device, not to Facebook itself. The Open Graph stories are not being posted in the users' Activity Log, and I was unable to get scores from users across devices. Has anybody done anything recently with the Facebook SD$$anonymous$$ 5.1 and Unity 4.5.2f1. The FriendSmash example app won't even log on for me when I try with that
Your answer
Follow this Question
Related Questions
Read JSON from Facebook? 0 Answers
How to parse Json file in android? 3 Answers
JSON Seriallize facebook name 1 Answer
Parsing Facebook graph JSON 1 Answer
Facebook SDK for Unity: check if an invite has been sent and give award to the player 1 Answer