所以我在Unity中使用Facebook API,并试图获得朋友的总数。我确实设法获得了姓名和个人资料图片。我想我已经很遥远了,但是为了使它正常工作,我只缺少了那一行代码。
public class FbScript : MonoBehaviour
{
public GameObject FullName;
public GameObject NumFriends;
void DealWithFBMenus(bool isLoggedIn)
{
if (isLoggedIn)
{
DialogLoggedIn.SetActive(true);
DialogLoggedOut.SetActive(false);
FB.API("/me/picture?type=square&height=128&width=128", HttpMethod.GET, DisplayProfilePic);
FB.API("/me?fields=name", HttpMethod.GET, DisplayUsername);
FB.API("/me?fields=first_name", HttpMethod.GET, DisplayFirstUsername);
FB.API("/me/friends?summary=total_count", HttpMethod.GET, DisplayFriends);
foreach (string perm in AccessToken.CurrentAccessToken.Permissions)
{
// log each granted permission
Debug.Log(perm);
}
}
else
{
DialogLoggedIn.SetActive(false);
DialogLoggedOut.SetActive(true);
}
}
void DisplayUsername(IResult result)
{
Text Username = FullName.GetComponent<Text>();
if (result.Error == null)
{
Username.text = "" + result.ResultDictionary["name"];
}
else
{
Debug.Log(result.Error);
}
}
void DisplayFriends(IGraphResult result)
{
if (result.Error == null)
{
Text Friends = NumFriends.GetComponent<Text>();
Friends.text = "Friends:, " + result.ResultDictionary["total_count"];
}
else
{
Debug.Log(result.Error);
}
}
}
}