我在此处遵循示例代码:https: //code.google.com/p/google-api-dotnet-client/wiki/OAuth2#Service_Accounts
授权失败:DotNetOpenAuth.Messaging.ProtocolException:发送直接消息或获取响应时出错.
内部异常是System.Net.WebException:远程服务器返回错误:(400)错误请求.响应正文为空,响应URI为https://accounts.google.com/o/oauth2/token.
在下面的响应中,您将看到特定错误是invalid_grant.
这是我的代码:
var certificate = new X509Certificate2(CertificatePath, "notasecret", X509KeyStorageFlags.Exportable);
var provider = new AssertionFlowClient(GoogleAuthenticationServer.Description, certificate)
{
ServiceAccountId = "<...>@developer.gserviceaccount.com",
Scope = CalendarService.Scopes.Calendar.GetStringValue()
};
var authenticator = new OAuth2Authenticator<AssertionFlowClient>(provider, AssertionFlowClient.GetState);
var calendarService =
new CalendarService(new BaseClientService.Initializer()
{
Authenticator = authenticator
});
var eventList = calendarService.Events.List("<id of the calendar>").Execute();
Run Code Online (Sandbox Code Playgroud)
证书和ServiceAccountId是正确的.我有三重检查,并且好的措施重新生成了证书.在用于创建服务帐户的Google开发者帐户的API控制台中启用了Google Calendar API.此帐户不属于Google Apps域.
我还使用指定的AssertionFlowClient的ServiceAccountUser属性对此进行了测试.我现在认为这是必需的 - 在我使用手动创建的JWT成功测试CalendarService时(请参阅下面的手动创建OAuth令牌工程),当prn属性未包含在prn属性中时,我在尝试创建令牌时收到404错误声明(即不包括ServiceAccountUser).
Google Apps域配置
在Google Apps域中,我已授予对此服务帐户日历的访问权限.
客户名称:[snip] .apps.googleusercontent.com
API范围:
安装了NuGet包
请求和响应
POST https://accounts.google.com/o/oauth2/token …Run Code Online (Sandbox Code Playgroud) .net google-calendar-api jwt google-oauth google-api-dotnet-client
一个功能为零的简单示例应用程序显示内存利用率的惊人差异.
数字是私有字节并使用.NET 4.0.
框架因无所事事而臭名昭着,但我仍然对这种差异感到惊讶.作为使用WPF的成本,我可以期望使用WPF构建的应用程序在私有字节中消耗30-40MB的空间吗?