【发布时间】:2016-06-06 05:46:19
【问题描述】:
在我的应用程序中,我使用的是谷歌日历 API。 我为我的帐户以及少数用户创建了客户端 ID 和客户端密码。 当我运行应用程序时,如果我没有登录浏览器,它会要求我登录我的 gmail 帐户。一旦我登录到我的 gmail 帐户,我就可以在我的日历上成功获取/创建/更新/删除事件。
目前我使用我的日历 ID 登录到 gmail 帐户,我能够获取不同日历 ID 的事件,但是我无法通过另一个用户日历 ID 创建/更新/删除事件。
我的要求是,我已登录到我的 gmail id,比如说 abc@gmail.com,我能够获取日历 id xyz@gmail.com 的事件,但无法为日历 id 创建/更新/删除事件xyz@gmail.com
我在互联网上做了很多研究,但没有找到任何东西。据我所知,我们需要将授权+访问令牌传递给请求。我也试过了,但没有用。
请建议我应该怎么做才能达到这个要求。
calID = Convert.ToString(Session["CalenderId"]);
userSecret = Convert.ToString(Session["UserSecret"]);
if (!string.IsNullOrEmpty(calID) && !string.IsNullOrEmpty(userSecret))
{
using (var stream =
new FileStream(userSecret, FileMode.Open, FileAccess.Read))
{
string credPath = System.Environment.GetFolderPath(
System.Environment.SpecialFolder.Personal);
credPath = Path.Combine(credPath, ".credentials/calendar-dotnet-quickstart.json/" + calID);
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
// Response.Write("Credential file saved to: " + credPath);
}
// Create Google Calendar API service.
var service = new CalendarService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
希望您能理解我的要求。等待最早的回应。 谢谢。
【问题讨论】:
标签: c# google-api google-calendar-api google-oauth google-api-dotnet-client