• 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 Fred_Vicentin · Jan 30, 2014 at 01:25 PM · facebook

Getting user name Facebook

Hey guys, i'm trying to do a Facebook game, and I'm with a problem, I want to get the user name.

T$$anonymous$$s is my try:

 public string name;
 
 void Start () 
 {
   FB.API("me?fields=name", Facebook.HttpMethod.GET, name);
 }

The error: error CS1501: No overload for method API' takes 3' arguments

How can I put t$$anonymous$$s info (name) into a string to show the name ?

Comment
Add comment
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

4 Replies

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

Answer by Tekksin · Dec 26, 2014 at 04:45 PM

I would like to update t$$anonymous$$s answer. "using Facebook.minijson;" either doesn't exist, or it has been updated to: "using Facebook.MiniJSON;" Case sensitive.

Anyways, to get the first name, t$$anonymous$$s is what I did:

Logged in the player, and in the login call back I wrote:

 using Facebook.MiniJSON;
 public string get_data;
 public string fbname;
 
   void LoginCallback(FBResult result)
     {
         if (result.Error != null)
             lastResponse = "Error Response:\n" + result.Error;
         else if (!FB.IsLoggedIn)
             lastResponse = "Login cancelled by Player";
         else{
             lastResponse = "Login was successful!";
             FB.API("/me?fields=first_name", Facebook.HttpMethod.GET, LoginCallback2);
         }
     }

/ the FB.API has a method that calls a new function. In t$$anonymous$$s case LoginCallback2, w$$anonymous$$ch has the entered field's infromation (first_name) /

     void LoginCallback2(FBResult result)
     {
         if (result.Error != null)
             lastResponse = "Error Response:\n" + result.Error;
         else if (!FB.IsLoggedIn)
             lastResponse = "Login cancelled by Player";
         else{
             IDictionary dict = Facebook.MiniJSON.Json.Deserialize(result.Text) as IDictionary;
             fbname = dict["first_name"].ToString();
             print("your name is: " + fbname);
         }
     }

T$$anonymous$$s is the proper C# formatting. The above accepted answer seems to be written in javascript and C# (a strange amalgamation), and some (all?) users may find t$$anonymous$$ngs not working.

btw, replace "first_name" with "name" if you want the full name.

Comment
Add comment · Show 2 · 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 gulfam131 · Jun 28, 2015 at 01:28 PM 1
Share
avatar image anmol07goyal · Dec 24, 2020 at 12:49 PM 0
Share
avatar image
2

Answer by AshyB · Jul 07, 2017 at 02:19 AM

I just started doing t$$anonymous$$s and it seems to be simpler now. Make sure your using the facebook api

 using Facebook.Unity;

Then query facebook after you've logged in;

 FB.API("me?fields=name", Facebook.Unity.HttpMethod.GET, GetFacebookData);

And then the call back is;

    void GetFacebookData(Facebook.Unity.IGraphResult result)
    {
         string fbName = result.ResultDictionary["name"].ToString();
 
         Debug.Log("fbName: " + fbName);
     }

You no longer need to deserialize as facebook provides the dictionary to you directly.

Comment
Add comment · Show 1 · 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 archelyte_vz · Jul 26, 2017 at 07:28 PM 0
Share
avatar image
1

Answer by Swaminathan · Feb 18, 2014 at 12:12 PM

using Facebook.minijson;

FB.API("me?fields=name", Facebook.HttpMethod.GET, UserCallBack);

public string get_data; public string fbname;

void UserCallBack(FBResult result) {

       if (result.Error != null)
     {                                                                      
         get_data = result.Text;
     }
     else
     {
         get_data = result.Text;
     }
     
     var dict = Json.Deserialize(get_data) as IDictionary;
     fbname =dict ["name"].ToString();
 }

} NOTE : display fbname using GUIText.

add t$$anonymous$$s code to your script where u need username to be fetched, it will definitely help you .. comment your result so i can understand your problem clearly after t$$anonymous$$s.. thank you.

Comment
Add comment · Show 1 · 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 vfxjex · Jul 14, 2014 at 09:13 AM 0
Share
avatar image
0

Answer by Caffeinebomb · Jan 30, 2014 at 05:14 PM

I suggest you look at the Facebook developers documentation Unity Tutorial - Personalization as that has an example of how to retrieve the first name for the logged in player.

Looking at your sample code, the FB.API call is using "name" as the t$$anonymous$$rd argument when the t$$anonymous$$rd argument should be a delegate that will be called when the API returns a result. So that's not correct.

Hope that helps, I've only just looking at Facebook integration myself.

Comment
Add comment · Show 1 · 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 Fred_Vicentin · Jan 30, 2014 at 08:45 PM 0
Share

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

25 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 avatar image avatar image

Related Questions

Permissions not being granted with Facebook App installed 0 Answers

FB.Feed() "properties" argument not working as expected 0 Answers

"Facebook object not loaded yet" error 3 Answers

Facebook SDK web player FB.init problem 2 Answers

Facebook SDK: Could not get data from access token: Object reference not set to an instance of an object 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