【发布时间】:2016-03-01 02:58:40
【问题描述】:
所以,我花了很多时间在谷歌上搜索这个问题。基本上,这是我的验证码:
UserCredential credential;
using (var stream =
new FileStream(@"C:\Users\Marto\Desktop\project\MVC_2b\App_Data\client_secret.json", FileMode.Open, FileAccess.Read))
{
string credPath = System.Environment.GetFolderPath(
System.Environment.SpecialFolder.Personal);
credPath = Path.Combine(credPath, ".credentials/calendar-dotnet-quickstart");
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
}
// Create Google Calendar API service.
var service = new CalendarService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
ApiKey = "key",
});
这就是发生错误的地方:(Execute() 上的错误 401)
Calendar calendar=new Calendar();
calendar.Id = "Test";
service.Calendars.Insert(calendar).Execute();
这是我的错误:
“Google.GoogleApiException”类型的异常发生在 Google.Apis.dll 但未在用户代码中处理
补充资料:
Google.Apis.Requests.RequestError - 无效凭据 [401]
Errors [Message[Invalid Credentials] Location[Authorization - header] Reason[authError] Domain[global]]
我不确定我是否没有在授权下做正确的事情。
任何帮助将不胜感激,谢谢!
【问题讨论】:
-
您的视图是什么样的?
标签: c# api model-view-controller google-calendar-api