Facebook 连接到 Unity 中的 GameSparks 服务器失败
Facebook Connection Failed to GameSparks Server in Unity
我正在使用适用于 Unity 的 Facebook SDK 通过 FacebookConnectRequest 设置与 GameSparks 服务器的 Facebook 连接。但是,我收到了键 "accessToken" 和值 "NOTAUTHENTICATED" 的错误响应。错误的详细信息是 "The system was unable to authenticate the token.".
我尝试在 Unity 中重新导入 Facebook 和 GameSparks SDK。更改代码中Facebook和GameSpark的一些初始化。但是,我想不出解决办法。
public void ConnectPlayerViaFacebook()
{
ChangeCurrentText("Connecting Facebook With Server...");
Debug.Log("Connecting Facebook With GameSparks...");// first check if FB is ready, and then login //
// if it's not ready we just init FB and use the login method as the callback for the init method //
if (!FB.IsInitialized)
{
ChangeCurrentText("Initializing Facebook...");
Debug.Log("Initializing Facebook...");
FB.Init(ConnectGameSparksToGameSparks, null);
}
else
{
FB.ActivateApp();
ConnectGameSparksToGameSparks();
}
}
///<summary>
///This method is used as the delegate for FB initialization. It logs in FB
/// </summary>
private void ConnectGameSparksToGameSparks()
{
if (FB.IsInitialized)
{
FB.ActivateApp();
Debug.Log("Logging into Facebook...");
ChangeCurrentText("Logging into Facebook...");
var perms = new List<string>() { "public_profile", "email" };
FB.LogInWithReadPermissions(perms, (result) =>
{
if (FB.IsLoggedIn)
{
ChangeCurrentText("Logged in, Connecting Server via Facebook...");
new FacebookConnectRequest()
.SetAccessToken(AccessToken.CurrentAccessToken.TokenString)
.SetDoNotCreateNewPlayer(false)
.SetDoNotLinkToCurrentPlayer(false)
.SetSwitchIfPossible(false)
.SetSyncDisplayName(true)
.Send((fbauth_response) =>
{
if (!fbauth_response.HasErrors)
{
...
}
else
{
Debug.Log(fbauth_response.Errors.JSON.ToString());
ChangeCurrentText("Server Authentication with Facebook Failed!" + fbauth_response.Errors.JSON.ToString());
}
});
}
else
{
Debug.LogWarning("Facebook Login Failed!" + result.Error.ToString());
ChangeCurrentText("Facebook Login Failed!" + result.Error.ToString());
}
});
}
else
{
ConnectPlayerViaFacebook(); // If we are still not connected, then try to process again
}
}
我想去掉 GameSparks 请求的 FacebookConnectRequest 的错误响应。
感谢derHugo的指点,我已经解决了这个问题。由于某些原因,访问令牌在 FacebookConnectionRequest 之前被破坏。为了防止访问令牌出现任何不良情况,需要手动刷新它。为此,需要在 FacebookConnectionRequest 之前使用 FB.Mobile.RefreshCurrentAccessToken。
该功能的解释如下:可能需要手动刷新用户授予应用程序的当前访问令牌以检索 up-to-date 权限,并延长到期日期,如果扩展是可能的。使用 FB.Mobile.RefreshCurrentAccessToken 来完成这个。 (source)
if (FB.IsLoggedIn)
{
FB.Mobile.RefreshCurrentAccessToken(callback =>
{
...
});
ChangeCurrentText("Logged in, Connecting Server via Facebook...");
new FacebookConnectRequest()
.SetAccessToken(AccessToken.CurrentAccessToken.TokenString)
.SetDoNotCreateNewPlayer(false)
.SetDoNotLinkToCurrentPlayer(false)
.SetSwitchIfPossible(false)
.SetSyncDisplayName(true)
.Send((fbauth_response) =>
{
...
});
}
else
{
...
}
我正在使用适用于 Unity 的 Facebook SDK 通过 FacebookConnectRequest 设置与 GameSparks 服务器的 Facebook 连接。但是,我收到了键 "accessToken" 和值 "NOTAUTHENTICATED" 的错误响应。错误的详细信息是 "The system was unable to authenticate the token.".
我尝试在 Unity 中重新导入 Facebook 和 GameSparks SDK。更改代码中Facebook和GameSpark的一些初始化。但是,我想不出解决办法。
public void ConnectPlayerViaFacebook()
{
ChangeCurrentText("Connecting Facebook With Server...");
Debug.Log("Connecting Facebook With GameSparks...");// first check if FB is ready, and then login //
// if it's not ready we just init FB and use the login method as the callback for the init method //
if (!FB.IsInitialized)
{
ChangeCurrentText("Initializing Facebook...");
Debug.Log("Initializing Facebook...");
FB.Init(ConnectGameSparksToGameSparks, null);
}
else
{
FB.ActivateApp();
ConnectGameSparksToGameSparks();
}
}
///<summary>
///This method is used as the delegate for FB initialization. It logs in FB
/// </summary>
private void ConnectGameSparksToGameSparks()
{
if (FB.IsInitialized)
{
FB.ActivateApp();
Debug.Log("Logging into Facebook...");
ChangeCurrentText("Logging into Facebook...");
var perms = new List<string>() { "public_profile", "email" };
FB.LogInWithReadPermissions(perms, (result) =>
{
if (FB.IsLoggedIn)
{
ChangeCurrentText("Logged in, Connecting Server via Facebook...");
new FacebookConnectRequest()
.SetAccessToken(AccessToken.CurrentAccessToken.TokenString)
.SetDoNotCreateNewPlayer(false)
.SetDoNotLinkToCurrentPlayer(false)
.SetSwitchIfPossible(false)
.SetSyncDisplayName(true)
.Send((fbauth_response) =>
{
if (!fbauth_response.HasErrors)
{
...
}
else
{
Debug.Log(fbauth_response.Errors.JSON.ToString());
ChangeCurrentText("Server Authentication with Facebook Failed!" + fbauth_response.Errors.JSON.ToString());
}
});
}
else
{
Debug.LogWarning("Facebook Login Failed!" + result.Error.ToString());
ChangeCurrentText("Facebook Login Failed!" + result.Error.ToString());
}
});
}
else
{
ConnectPlayerViaFacebook(); // If we are still not connected, then try to process again
}
}
我想去掉 GameSparks 请求的 FacebookConnectRequest 的错误响应。
感谢derHugo的指点,我已经解决了这个问题。由于某些原因,访问令牌在 FacebookConnectionRequest 之前被破坏。为了防止访问令牌出现任何不良情况,需要手动刷新它。为此,需要在 FacebookConnectionRequest 之前使用 FB.Mobile.RefreshCurrentAccessToken。
该功能的解释如下:可能需要手动刷新用户授予应用程序的当前访问令牌以检索 up-to-date 权限,并延长到期日期,如果扩展是可能的。使用 FB.Mobile.RefreshCurrentAccessToken 来完成这个。 (source)
if (FB.IsLoggedIn)
{
FB.Mobile.RefreshCurrentAccessToken(callback =>
{
...
});
ChangeCurrentText("Logged in, Connecting Server via Facebook...");
new FacebookConnectRequest()
.SetAccessToken(AccessToken.CurrentAccessToken.TokenString)
.SetDoNotCreateNewPlayer(false)
.SetDoNotLinkToCurrentPlayer(false)
.SetSwitchIfPossible(false)
.SetSyncDisplayName(true)
.Send((fbauth_response) =>
{
...
});
}
else
{
...
}