Asp.net mvc 4 谷歌日历-从azure插入事件不起作用
我有一个要求,在应用程序的完整日历中插入事件时,我需要更新用户的google日历。我正在使用peleyal的ASP.NETMVC示例和用于GoogleAPI的OAuth(使用GoogleAuthorizationCodeFlow和AuthorizationCodeMvcApp)来处理这个问题。我相信我已经在google开发者控制台中设置了凭据 我可以在谷歌日历上本地创建事件,而不会出现问题。但是从azure部署的站点我无法创建事件。也没有例外/错误要创建事件并使用Google API,azure端是否需要做任何事情?Asp.net mvc 4 谷歌日历-从azure插入事件不起作用,asp.net-mvc-4,azure,google-api,google-calendar-api,google-api-dotnet-client,Asp.net Mvc 4,Azure,Google Api,Google Calendar Api,Google Api Dotnet Client,我有一个要求,在应用程序的完整日历中插入事件时,我需要更新用户的google日历。我正在使用peleyal的ASP.NETMVC示例和用于GoogleAPI的OAuth(使用GoogleAuthorizationCodeFlow和AuthorizationCodeMvcApp)来处理这个问题。我相信我已经在google开发者控制台中设置了凭据 我可以在谷歌日历上本地创建事件,而不会出现问题。但是从azure部署的站点我无法创建事件。也没有例外/错误要创建事件并使用Google API,azure
var finalREsult = System.Threading.Tasks.Task.Run(async () =>
{
try
{
var result = await new AuthorizationCodeMvcApp(this, new AppFlowMetaData()).AuthorizeAsync(cancellationToken);
if (result.Credential != null)
{
var service = new CalendarService(new BaseClientService.Initializer
{
HttpClientInitializer = result.Credential,
ApplicationName = "****"
});
var startDate = patientappointment.DateScheduled.Value.ToUniversalTime();
var endDate = patientappointment.DateScheduled.Value.AddMinutes(patientappointment.AppointmentLengthMinutes).ToUniversalTime();
var myEvent = new Event
{
Summary = string.Format("{0}/{1}/{2} - {3}", patientappointment.CurrentUserName, patientappointment.LocationName, patientappointment.RoomName, patientappointment.Notes),
Location = "Ireland",
Start = new EventDateTime
{
DateTime = new DateTime(startDate.Year, startDate.Month, startDate.Day, startDate.Hour, startDate.Minute, 0),
TimeZone = "(GMT+01:00) Dublin"
},
End = new EventDateTime
{
DateTime = new DateTime(endDate.Year, endDate.Month, endDate.Day, endDate.Hour, endDate.Minute, 0),
TimeZone = "(GMT+01:00) Dublin"
},
Recurrence = new String[] { "RRULE:FREQ=WEEKLY;BYDAY=MO" }
// Attendees = new List<EventAttendee> { new EventAttendee { Email = "**0@gmail.com" } },
};
EventsResource.InsertRequest request = service.Events.Insert(myEvent, "******@group.calendar.google.com");
request.Execute();
}
}
catch (Exception ex)
{
throw ex;
}
你能把授权代码的cod寄出去吗?那它是什么类型的azure服务器呢?你可能想看看这个。我不确定您是如何保存身份验证的,但我想知道免费的azure web服务器是否允许您写入%appdata%,这是filedatastore存储其数据的地方。@DaImTo:我使用的是中可用的AuthorizationCodeMvcApp的默认实现。我不使用免费的azure web服务器,因为我有信用卡,也有自定义域名。我们可以不访问appdata吗?我每次都会得到身份验证代码和令牌,而不是将其保存在appdata(或任何地方)中。奇怪的是,这在本地主机中有效,但在部署的azure中无效。我已经创建了url参数ApprovalPrompt=“force”。@DaImTo:我已经添加了我已经覆盖的类,用于将其自定义到原始代码段中。请查克。谢谢,如果内存服务,如果您不提供数据存储,客户端库将默认使用filedatastore。因此,它可能正试图保存到%appdata%。您已将azure服务器的重定向uri添加到开发人员控制台,对吗?
internal class ForceOfflineGoogleAuthorizationCodeFlow : GoogleAuthorizationCodeFlow
{
public ForceOfflineGoogleAuthorizationCodeFlow
(AuthorizationCodeFlow.Initializer initializer)
: base((GoogleAuthorizationCodeFlow.Initializer)initializer) { }
public override AuthorizationCodeRequestUrl CreateAuthorizationCodeRequest(string redirectUri)
{
return new GoogleAuthorizationCodeRequestUrl(new Uri(AuthorizationServerUrl))
{
ResponseType = "code",
ClientId = ClientSecrets.ClientId,
Scope = string.Join(" ", Scopes),
RedirectUri = redirectUri,
AccessType = "offline",
ApprovalPrompt = "force",
State = ""
};
}
};
public class AppFlowMetaData : FlowMetadata
{
private static readonly IAuthorizationCodeFlow flow = new ForceOfflineGoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer
{
ClientSecrets = new ClientSecrets
{
ClientId = ConfigurationManager.AppSettings["ClientId"],
ClientSecret = ConfigurationManager.AppSettings["ClientSecret"]
},
Scopes = new[] { CalendarService.Scope.Calendar },
DataStore = null
});
public override string GetUserId(System.Web.Mvc.Controller controller)
{
return "user1";
}
public override IAuthorizationCodeFlow Flow
{
get { return flow; }
}
}