Google Api GameService没有个别错误 - .NET

时间:2016-11-25 19:21:23

标签: c# .net google-api-client google-api-dotnet-client

我正在尝试使用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错误吗?

1 个答案:

答案 0 :(得分:1)

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