Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Sospitas · Jul 30, 2014 at 03:53 PM · facebookjson

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

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image $$anonymous$$ · Jul 30, 2014 at 04:04 PM 0
Share

can you show us this part of code? :

 FB.Login(Permissions, LoginCallback);

avatar image Sospitas · Jul 30, 2014 at 04:06 PM 0
Share
 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?

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Sospitas · Jul 31, 2014 at 10:44 AM 0
Share

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

avatar image smallbit · Jul 31, 2014 at 10:55 AM 0
Share

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

avatar image Sospitas · Jul 31, 2014 at 02:51 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

23 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges