C# 接收(401)未经授权的google日历API
我在谷歌日历API方面遇到了一些问题。我试图在日历上创建一个偶数,但我在查询日历服务时遇到了麻烦。我正在使用我在codeproject()上找到的这个指南,它将您链接到这个身份验证指南()。我能够在《身份验证指南》的“OAuth 2.0流”下完成第5步,并获得了访问令牌和刷新令牌,但当我尝试查询日历服务时,出现以下错误: 执行请求失败:“,”远程服务器返回错误:(401)未经授权 我不确定我做错了什么,我授权了用户并拥有访问令牌。所以我会认为我错过了一些小东西,但我在过去的一天里一直在努力寻找答案 这是我正在使用的代码:C# 接收(401)未经授权的google日历API,c#,asp.net,google-api,google-calendar-api,C#,Asp.net,Google Api,Google Calendar Api,我在谷歌日历API方面遇到了一些问题。我试图在日历上创建一个偶数,但我在查询日历服务时遇到了麻烦。我正在使用我在codeproject()上找到的这个指南,它将您链接到这个身份验证指南()。我能够在《身份验证指南》的“OAuth 2.0流”下完成第5步,并获得了访问令牌和刷新令牌,但当我尝试查询日历服务时,出现以下错误: 执行请求失败:“,”远程服务器返回错误:(401)未经授权 我不确定我做错了什么,我授权了用户并拥有访问令牌。所以我会认为我错过了一些小东西,但我在过去的一天里一直在努力寻找答
Google.GData.Client.GAuthSubRequestFactory authFactory = new Google.GData.Client.GAuthSubRequestFactory("cl", "API Project");
authFactory.Token = "ya29...";
authFactory.KeepAlive = true;
Google.GData.Calendar.CalendarService service = new CalendarService("API Project");
service.RequestFactory = authFactory;
Uri postUri = new Uri(AllCalendarFeed);
Google.GData.Calendar.CalendarQuery CalendarQuery = new Google.GData.Calendar.CalendarQuery();
CalendarQuery.Uri = postUri;
//Errors out on this line:
Google.GData.Calendar.CalendarFeed calFeed = service.Query(CalendarQuery);
string CalendarID = "";
if (calFeed != null && calFeed.Entries.Count > 0)
{
foreach (CalendarEntry CalEntry in calFeed.Entries)
{
//Commented to post the new appointments
//on the main calendar instead of cleverfox calendar
//if (CalEntry.Title.Text.Contains("Cleverfox") == true)
//{
//CalendarID = CalEntry.Title.Text;
CalendarID = CalEntry.EditUri.ToString().Substring(CalEntry.EditUri.ToString().LastIndexOf("/") + 1);
break;
//}
}
}
非常感谢您的帮助。谢谢。我假设实际的代码在您放置的地方有完整的标记
authFactory.token=“ya29…”代码>?否则,这似乎太短了。还有,你确定你没有把它们倒过来吗?你想当然了。我只是不知道这些信息有多敏感。我很肯定我是对的。