谷歌日历API V3 C#不工作
问题描述:
我尝试使用谷歌日历API V3让我的日历,使用C#与服务占公司给予出错谷歌日历API V3 C#不工作
错误。
以下是我的代码。
private const string SERVICE_ACCOUNT_EMAIL = "[email protected]";
private const string SERVICE_ACCOUNT_PKCS12_FILE_PATH = @"D:\privatekey.p12";
static void Main(string[] args)
{
Test();
}
static void Test()
{
X509Certificate2 certificate = new X509Certificate2(SERVICE_ACCOUNT_PKCS12_FILE_PATH, "notasecret", X509KeyStorageFlags.Exportable);
AssertionFlowClient provider = new AssertionFlowClient(GoogleAuthenticationServer.Description, certificate)
{
ServiceAccountId = SERVICE_ACCOUNT_EMAIL,
Scope = "Calendar",
};
var auth = new OAuth2Authenticator<AssertionFlowClient>(provider, AssertionFlowClient.GetState);
CalendarService c1 =new CalendarService(
new BaseClientService.Initializer()
{
Authenticator = auth
});
c1.Calendars.Get("MyCalenderID").Fetch();
}
答
你的范围应该是:
"https://www.googleapis.com/auth/" +
Google.Apis.Calendar.v3.CalendarService.Scopes.CalendarReadonly.ToString().ToLower()