我正在使用 PlayFab 在我的 Desktop Unity 游戏中创建帐户。我想允许用户在我的游戏中使用谷歌登录。但是,我不知道如何获取 LoginWithGoogleAccountRequest 需要的服务器身份验证代码:
我的代码看起来像这样:
using PlayFab;
using PlayFab.ClientModels;
using UnityEngine;
public class LoginManager: MonoBehaviour
{
string GetServerAuthCode() {
}
void LoginUsingGoogle() {
var request = new LoginWithGoogleAccountRequest { CreateAccount = true, ServerAuthCode = GetServerAuthCode()};
PlayFabClientAPI.LoginWithGoogleAccount(request, OnLoginUsingThirdPartySuccess, OnLoginUsingThirdPartyFailure);
}
}
我想在
GetServerAuthCode
下编写适当的代码。
我知道如何获取令牌,但我不知道如何获取服务器授权码:
public string GetToken() {
string[] scopes = {"https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/userinfo.profile"};
var credentials = GoogleWebAuthorizationBroker.AuthorizeAsync(
new ClientSecrets {
ClientId = ClientId,
ClientSecret = SecretKey,
}, scopes, "user", CancellationToken.None);
return credentials.Result.Token.AccessToken;
}
根据Google docs,不支持Windows平台(他们支持Android/iOS/Web)。如果你
您必须按照本教程构建自己的 OAuth 2.0 处理程序(点击我) Github 上的桌面 OAuth 示例 您需要按照上述教程才能获取授权码/令牌。拥有它后,您就可以正常使用 PlayFab API 来使用 LoginWithGoogleAccount 并将请求中的令牌作为 ServerAuthCode 发送。
重要提示:您必须修改 PlayFab 代码以在请求中包含访问令牌,因为它现已弃用。