【问题标题】:FB.Api error on unityFB.Api 统一错误
【发布时间】:2017-08-10 19:34:46
【问题描述】:

我在 Unity 3D 上获取 facebook 名称时出错,这个功能在 2 周前就可以正常工作了,

FB.Init(this.InitCallback, this.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)

【问题讨论】:

    标签: unity3d facebook-unity-sdk


    【解决方案1】:

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

    FB.IsInitialized == true

    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);
                    }
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-08
      • 1970-01-01
      • 2015-07-21
      • 1970-01-01
      • 1970-01-01
      • 2022-10-25
      • 1970-01-01
      相关资源
      最近更新 更多