c# - Unity - 尝试使用 GooglePlay 服务将播放器登录到 GooglePlay
问题描述
我正在尝试使用 GooglePlay 服务将玩家登录到 GooglePlay。该应用程序已发布。开始游戏时,您应该使用 GooglePlay 自动登录,但没有任何反应。这是我使用的代码。如果有人可以在这个话题上帮助我,我将不胜感激。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GooglePlayGames;
using UnityEngine.SocialPlatforms;
using GooglePlayGames.BasicApi;
public class GooglePlayServices : MonoBehaviour
{
void Start()
{
Initialize();
}
private void Initialize()
{
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
.RequestServerAuthCode(false).
Build();
PlayGamesPlatform.InitializeInstance(config);
PlayGamesPlatform.Activate();
SignInUserWithPlayGames();
}
void SignInUserWithPlayGames()
{
PlayGamesPlatform.Instance.Authenticate(SignInInteractivity.CanPromptOnce, (success) =>
{
switch(success)
{
case SignInStatus.Success:
Debug.Log("Signed in Player successfully");
break;
default:
Debug.Log("Login failed");
break;
}
});
}
public void SignInByHand()
{
PlayGamesPlatform.Instance.Authenticate(SignInInteractivity.CanPromptAlways, (success) =>
{
});
}
public void SignOut()
{
PlayGamesPlatform.Instance.SignOut();
}
}
解决方案
private void Initialize()
{
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().RequestServerAuthCode(false).Build();
PlayGamesPlatform.InitializeInstance(config);
PlayGamesPlatform.DebugLogEnabled = true;
PlayGamesPlatform.Activate();
SignInUserWithPlayGames();
}
void SignInUserWithPlayGames()
{
if (!Social.localUser.authenticated)
{
Social.localUser.Authenticate(success => {
if(success)
{
// signed in
}
});
}
}
尝试使用社交而不是直接调用 Google Play 插件。如果我需要其他社交平台没有的特定功能,我只会直接调用插件。
推荐阅读
- python - Python 从另一个进程访问 Selenium Webdriver 实例
- azure - 在没有用户凭据的情况下将 Azure 自动化帐户登录到 Azure AD
- java - 找出特定时间范围是否在数组中空闲
- excel - 根据多个文件夹中不同工作簿的单元格值复制行
- flutter - 有没有办法从插件添加 JS 文件?
- internationalization - 如何在 AlpacaJS 表单中翻译国家字段?
- c# - Ajax 请求在 net core 2.2 中不起作用
- node.js - 使用 lamda 将字符串数据保存在 Dynamodb 中不起作用
- prolog - Prolog 真值集
- go - 使用 Kubernetes 集群 k8s 中的 SRV 记录通过 Golang 中的 DNS 实现对等发现逻辑