Shashank Shukla
Shashank Shukla

Reputation: 1146

How To Get User Name From Facebook Unity SDK

I am new in unity and trying to integrate Facebook unity SDK. But i am not able to find current logged-in user name. It will return only userId and accessToken. How to get login name after FB.Login("email")

Upvotes: 2

Views: 9132

Answers (3)

Neerkoli
Neerkoli

Reputation: 2695

After calling the API

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

get the exact name from the JSON like this:

void NameCallBack(FBResult result)
{
    IDictionary dict = Facebook.MiniJSON.Json.Deserialize(result.Text) as IDictionary;
    string fbname = dict["name"].ToString();
}

Upvotes: 3

Brian Jew
Brian Jew

Reputation: 906

After you login, you can get the name with:

FB.API("me?fields=name", Facebook.HttpMethod.GET, <your callback here>);

Upvotes: 8

Brooke Jackson
Brooke Jackson

Reputation: 113

My best guess if I was to look somewhere is to make use of that userId and FQL to query Facebook for the name of the user.

For instance using the Graph API Explorer: https://developers.facebook.com/tools/explorer

I used the following query:

Select name from user where uid = [userId]

It returned the following JSON string:

{
  "data": [
    {
      "name": "myName"
    }
  ]
}

I think you can use https://developers.facebook.com/docs/php/howto/profilewithfql/ to get an idea of how to query the FB.API to perform a FQL query.

FQL Guide: https://developers.facebook.com/docs/technical-guides/fql/

Upvotes: 1

Related Questions