我试图使用GameService API列出游戏AchievementDefinitions,但始终返回[500]没有单独的错误。我正在使用ServiceAccountCredential进行身份验证。

我尝试了两种方式进行身份验证

string credPath = @"C:\Downloads\game-bd201016b65f.json";
var json = File.ReadAllText(credPath);
var cr = JsonConvert.DeserializeObject<dynamic>(json);

var xCred = new ServiceAccountCredential(new ServiceAccountCredential.Initializer(cr.client_email.ToString())
{
    Scopes = new[] { GamesService.Scope.Games }
}.FromPrivateKey(cr.private_key.ToString()));

var initializer = new BaseClientService.Initializer()
{
    HttpClientInitializer = xCred
};

GamesService gamesService = new GamesService(initializer);
var a = gamesService.AchievementDefinitions.List().Execute();




GoogleCredential credential;
using (var stream = new FileStream(@"C:\game-bd201016b65f.json", FileMode.Open, FileAccess.Read, FileShare.Read))
{
    credential = GoogleCredential.FromStream(stream);
}

if (credential.IsCreateScopedRequired)
{
    credential = credential.CreateScoped(GamesService.Scope.Games);
}

var initializer = new BaseClientService.Initializer()
{
    HttpClientInitializer = credential
};


在.NET中运行时会出现API错误吗?

最佳答案

GameService API用于获取用户身份验证信息,而我需要获取Game信息,要获取游戏信息,需要使用GameService Management API。
使用GameService Management API,我可以通过ServiceAccountCredential进行身份验证并获取游戏信息。

10-06 03:35