FB.关于统一的 API 错误



我在Unity 3D上获取Facebook名称时出错,此功能显然在2周前有效,

FB.初始化(这个。初始化回调,这个。OnHideUnity(;

private void InitCallback ()
{
if (FB.IsInitialized) {
if (FB.IsLoggedIn) {
FB.LogInWithReadPermissions(new List<string>() { "public_profile","email" }, this.AuthCallback);
} else {
}
} else {
Debug.Log("Failed to Initialize the Facebook SDK");
}
}
private void AuthCallback (ILoginResult result) {
if (FB.IsLoggedIn) {
FB.API("/me?fields=name", HttpMethod.GET, this.LoginCallback2);
} else {
//Debug.Log("User cancelled login");
}
}
void LoginCallback2(IResult result)
{
if (result.Error != null) {
Debug.Log(result.Error);
}
else{
fbid = result.ResultDictionary ["id"].ToString();
}
}

我在 LoginCallback2 函数上遇到错误,调试如下:

UnityEngine.Debug:Log(Object)
connect:LoginCallback2(IResult) (at Assets/connect.cs:983)
Facebook.Unity.<Start>d__9:MoveNext()
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

简短的回答是FB尚未初始化,或者用户未登录。下面我分享了我自己的代码,用于检索用户的全名和他们的 FBID。在调用此代码部分之前,您需要检查以确保以下内容为真:

FB.初始化 == 真

FB.IsLoggedIn == true

if (result != null) {
if (string.IsNullOrEmpty(result.Error)) {
if (result.ResultDictionary != null)
if (result.ResultDictionary.ContainsKey("name")) {
result.ResultDictionary.TryGetValue("name", out Name);
}
if (result.ResultDictionary != null)
if (result.ResultDictionary.ContainsKey("id")) {
result.ResultDictionary.TryGetValue("id", out FBID);
}
}
}

相关内容

最新更新