Setting reminders in google calendar through .net api - asp.net

I am writing an asp.net webpage that creates events in google calendar. I want to add a "notification" to the event that will send an email 30 minutes before the event begins.
Reading through the api, I see that there is an attribute for inserting events called "reminders" that seems to be the same thing. Using google's api playground, I can successfully create the event and specify the reminder.
However, using the .net api version 1.9.0.990 I can create the event, but no reminders are set for it. Below is the code I have written:
Shared Sub eventWithReminder(calendarIdentifier As String, startTime As DateTime, endTime As DateTime, eventTitle As String)
Dim calendarID As String
Dim calList As CalendarList = RoomReservations_RoomReservationsServiceAccount.calService.CalendarList.List().Execute
For Each Calendar In calList.Items
If Calendar.Id = calendarIdentifier Then
calendarID = Calendar.Id
End If
Next
Dim anotherNewEvent As New [Event]
anotherNewEvent.Summary = eventTitle
Dim edtStart As New EventDateTime
edtStart.DateTime = startTime
Dim edtEnd As New EventDateTime
edtEnd.DateTime = endTime
anotherNewEvent.Start = edtStart
anotherNewEvent.End = edtEnd
Dim reminder As New EventReminder
reminder.Method = "email"
reminder.Minutes = 30
Dim reminderList As New List(Of EventReminder)
reminderList.Add(reminder)
Dim remindData As New [Event].RemindersData
remindData.UseDefault = False
remindData.Overrides = reminderList
anotherNewEvent.Reminders = remindData
System.Net.ServicePointManager.Expect100Continue = False
RoomReservations_RoomReservationsServiceAccount.calService.Events.Insert(anotherNewEvent, calendarID).Execute()
End Sub
I then view the event in the google calendar web interface, but the Notifications section reads "No notifications set"
Is this functionality not yet built in to the api?
If it is, am I using it incorrectly?

Reminders are tied to the authenticated user. In this case Bob was creating events using service account but on user's calendar. Service accounts do not have privileges to modify reminders for users.
In order to change reminders for someone, you need to be authenticated as that person (use their Oauth token).

Related

How to pass the asp.Identity object to a second register page

I am building a much more advanced registration process which consists of 3 pages, the first page is a form that grabs a username(email form) and a password with confirmation. The button click on this page creates the user in an unverified state in the db and redirects to the page where the profile is created. Once the create profile button is clicked and the profile is created in the db the redirect takes you to the Credit Card info page where the form is filled out, the credit card is verified and then that info is written to a table in the database.
I have disabled the loggedin user display in the header so that I can use the registrants First and Last name which arent entered until the Credit Card page. Since the identityUser is required for the sign on and thus to populate the loggedin user control, how can I pass this object from page to page?
Code where original template was logging in the user: (Note:I commented out the sign in code)
Protected Sub CreateUser_Click(sender As Object, e As EventArgs)
Dim userName As String = UserNameCtrl.Text
Dim manager = New UserManager()
Dim newuser = New IdentityUser() With {.UserName = userName}
manager.UserValidator = New UserValidator(Of IdentityUser)(manager) With {.AllowOnlyAlphanumericUserNames = False}
Dim result = manager.Create(newuser, Password.Text)
If result.Succeeded Then
Session("email") = newuser.UserName
Session("userid") = newuser.Id.ToString()
'uncomment the code below if you want the auto sign in to occur
'IdentityHelper.SignIn(manager, newuser, isPersistent:=False)
IdentityHelper.RedirectToReturnUrl(Page.ResolveUrl("~/Account/CreateProfile.aspx?Guid=" & newuser.Id.ToString()), Response)
Else
ErrorMessage.Text = Encoder.HtmlEncode(result.Errors.FirstOrDefault())
End If
End Sub
I now call this routine to sign in the user once the third page of the registration process is completed. (Session("userid") is the new registrants generated userid)
Private Sub SignInUserOnFormCompletion()
Dim manager = New UserManager()
manager.UserValidator = New UserValidator(Of IdentityUser)(manager) With {.AllowOnlyAlphanumericUserNames = False}
Dim newuser = New IdentityUser() With {.Id = Session("userid").ToString()}
IdentityHelper.SignIn(manager, newuser, isPersistent:=False)
End Sub
The problem is the above doesnt work as the newuser somehow has different credentials. How can I pass the original newuser from the first page to the third page where I can use it in the SignInUserOnFormCompletion subroutine? Do I create a cookie and pass it around that way?
This is a new topic for me so I'm not familiar with the proper methods to accomplish this.
If you use multiple pages arranged as a wizard, then you will need to pass data between the pages.
However, if you use a single page with a MultiView or Wizard control, then you won't need to do that. Just arrange your current pages as separate views within the MultiView, and use Session state to retain data across the post backs.

Batch processing with Google Calendar V3 API

I've been working with the new google Calendar V3 API and I've coded all my class methods to process Adds, Updates, retrievals etc but I was wondering if there is a way to send a batch of adds + updates + deletes all at once rather than sending each request separately and possible exceeding the trans/sec threshold. I understand the .Batch method has been depreciated in V3 and I found another methodology that uses web services that will notify a client that changes are ready but I'm trying to do this from a .NET Winform application so it needs to be something initiated from the client and not dependent upon online services or a PUSH methodology.
Regards,
Kerry
I got this to work using the BatchRequest object:
Dim initializer As New BaseClientService.Initializer()
initializer.HttpClientInitializer = credential
initializer.ApplicationName = "My App"
Dim service = New CalendarService(initializer)
'fetch the calendars
Dim list = service.CalendarList.List().Execute().Items()
'get the calendar you want to work with
Dim calendar = list.First(Function(x) x.Summary = "{Calendar Name}")
Dim br As New Google.Apis.Requests.BatchRequest(service)
'make 5 events
For i = 1 To 5
'create a new event
Dim e As New [Event]
'set the event properties
e.Summary = "Test Event"
e.Description = "Test Description"
e.Location = "Test Location"
...
'make a request to insert the event
Dim ins As New InsertRequest(service, e, calendar.Id)
'queue the request
br.Queue(Of Dummy)(ins, AddressOf OnResponse)
Next
'execute the batch request
Dim t = br.ExecuteAsync()
'wait for completion
t.Wait()
For some reason, you can't have a deferred request without specifying a callback to the Queue method, and that method requires a generic type parameter. So I defined the following:
Class Dummy
End Class
Sub OnResponse(content As Dummy, err As Google.Apis.Requests.RequestError, index As Integer, message As System.Net.Http.HttpResponseMessage)
End Sub
With this in place, the batch inserts worked fine.

Create an Appointment with EWS in VB.NET, what am i missing?

Hello i want to send a calendar invite to other members, how can i do that in vb.net,
i added the exchange webreference and can send a normal mail to other people.
here is what i have so far
Public Sub Einladungen()
Dim esb As New ExchangeServer.ExchangeServiceBinding
esb.Credentials = New NetworkCredential(Session("EX_UserName").ToString, Session("EX_Password").ToString)
esb.Url = Session("EX_DomainURL")
Dim appointment As CalendarItemType = New CalendarItemType
' Set properties on the appointment.
appointment.Subject = "Dentist Appointment"
appointment.Body = New BodyType
appointment.Body.BodyType1 = BodyTypeType.Text
appointment.Body.Value = "Agenda Items...."
appointment.Start = New DateTime(2012, 3, 1, 9, 0, 0)
appointment.End = appointment.Start.AddHours(2)
appointment.Location = "Conf Room"
appointment.RequiredAttendees.Add("user1#contoso.com")
appointment.RequiredAttendees.Add("user2#contoso.com")
appointment.OptionalAttendees.Add("user3#contoso.com")
' Save the appointment.
appointment.Save(SendInvitationsMode.SendToAllAndSaveCopy)
End Sub
Visual Studio tells me that:
Add is not a member of "System.Array"
and
"Save" is not a member of "ExchangeServer.CalendarItemType"
and
The name "SendInvitationMode" is not declared
What am i missing?
Thanks in advance for your help
The problem is that you have created your own EWS proxy classes by referencing your Exchange web service directly but the sample code you have found is built using the Exchange Web Service Managed API.
So what you should do is to download the EWS Managed API, add a reference to Microsoft.Exchange.WebServices.dll, and change the beginning of your code into something similar to this:
Dim esb As New ExchangeService(ExchangeVersion.Exchange2007_SP1);
esb.Credentials = New NetworkCredential(Session("EX_UserName").ToString, Session("EX_Password").ToString)
esb.Url = Session("EX_DomainURL")
Dim appointment As new Appointment(esb);
// ... the rest of your code here.
You might want to have a look at this example:
http://msdn.microsoft.com/en-us/library/exchange/dd633661(v=exchg.80).aspx

Getting an specific ProfileId from registered Accounts using GData .NET Analytics API 2.4

In a past entry I figured out how to retrieve the metrics data for a certain profile id:
Exception thrown when using GData .NET Analytics API
Now I would like to retrieve a certain profile id that matches a registered domain name on my accounts list in Google Analytics, this was easy before, but after the last Google upgrade to Management/Core Reporting API 3.0, the old 2.3 feed has been shutdown and the AccountsFeed related code is not working as expected.
Using a suggestion posted here: http://code.google.com/p/gdata-issues/issues/detail?can=2&start=0&num=100&q=&colspec=API%20ID%20Type%20Status%20Priority%20Stars%20Summary&groupby=&sort=&id=2955 , I came up with this code works to accomplish what I need:
Imports Google
Imports Google.Analytics
Imports Google.GData.Analytics
Imports System.Collections.Generic
Imports System.Collections
Public Function GetProfileId(ByVal DomainText As String) As String
Dim Ids As String = String.Empty
Dim service As GData.Analytics.AnalyticsService = New GData.Analytics.AnalyticsService("MyAnalyticsService")
service.setUserCredentials(username, pass)
//Dim factory As GData.Client.GDataGAuthRequestFactory = CType(service.RequestFactory, GData.Client.GDataGAuthRequestFactory)
//factory.AccountType = "GOOGLE"
//factory.UseSSL = True
//service.RequestFactory = factory
Dim aF As DataFeed = service.Query(New DataQuery("https://www.googleapis.com/analytics/v2.4/management/accounts"))
Dim webPropsUrl As String = ""
For Each o As GData.Client.AtomEntry In aF.Entries
//webproperties
If o.Title.Text.Contains(DomainText) Then
webPropsUrl = o.Links.Item(1).HRef.Content
Exit For
End If
Next
Dim wpF As DataFeed = service.Query(New DataQuery(webPropsUrl))
Dim profileFeedUrl As String = ""
For Each entry As DataEntry In wpF.Entries
//profiles
profileFeedUrl = entry.Links.Item(2).HRef.Content
Exit For
Next
Dim prF As DataFeed = service.Query(New DataQuery(profileFeedUrl))
Dim profileUrl As String = ""
For Each profd As DataEntry In prF.Entries
profileUrl = profd.Links.Item(0).HRef.Content
Exit For
Next
Dim profileId As String = ""
profileId = profileUrl.Split("/")(profileUrl.Split("/").Length - 1)
Return profileId
End Function

Exception thrown when using GData .NET Analytics API

I am facing an issue while trying to fetch data from GoogleAnalytics API on piece of code that has been working well just a couple of days ago.
For this I am referencing the following DLL's:
Google.GData.Analytics.dll
Google.GData.Client.dll
Google.GData.Extensions.dll
And I am using the following code:
Dim visits As String = String.Empty
Dim username As String = "myuser#mydomain.com"
Dim pass As String = "mypassword"
Const dataFeedUrl As String = "https://www.google.com/analytics/feeds/data"
Dim query As AccountQuery = New AccountQuery()
Dim service As AnalyticsService = New AnalyticsService("MyWebAnalyticsService")
service.setUserCredentials(username, pass)
Dim accountFeed As AccountFeed = service.Query(query) ''----------> Exception thrown in this line: GDataRequestException Execution of request failed: https://www.google.com/analytics/feeds/accounts/default
I thought it had to do with a blocking to the account I was using but it wasn't the case because I verified registering the site for another analytics account and is still not working.
This code has been working flawlessly as I've said but all of a sudden has stopped doing so yesterday.
Could you please help me figuring out what's wrong?. Maybe the way the user credentials are set has changed and I am missing something.
Thank you very much for your help.
'----Update----
I managed to make it work and now I can query the visits for a desired domain. The code goes as follows:
Dim visits As String = String.Empty
Dim username As String = "myuser#mydomain.com"
Dim pass As String = "mypassword"
'Follow the instructions on https://developers.google.com/analytics/resources/articles/gdata-migration-guide (Create a Project in the Google APIs Console) to generate your key
'Once you have it set it as part of the querystring to request our GA service
Dim gkey As String = "key=yourkeystring"
'Set the new URI to retrieve the feed data and append it the generated key
Dim dataFeedUrl As String = "https://www.google.com/analytics/feeds/data?" & gkey
'Create and authenticate on our service instance
Dim service As AnalyticsService = New AnalyticsService("MyAnaliticsService")
service.setUserCredentials(username, pass)
'Use the profile id for the account you want to get ths visits from, you can find it
'logging in your analytics account, select the desired domain on your list (blue link)
click on the administrator button and on the profiles tab find the profile
'configuration subtab, right there you will find the profile id in this case the eight characters long id 12345678
Dim query1 As DataQuery = New DataQuery(dataFeedUrl)
With query1
.Ids = "ga:12345678"
.Metrics = "ga:visits"
.Sort = "ga:visits"
.GAStartDate = DateTime.Now.AddMonths(-1).AddDays(-2).ToString("yyyy-MM-dd")
.GAEndDate = DateTime.Now.ToString("yyyy-MM-dd")
.StartIndex = 1
End With
'Use the generated datafeed based on the former query to get the visits
Dim dataFeedVisits As DataFeed = service.Query(query1)
For Each entry As DataEntry In dataFeedVisits.Entries
Dim st As String = entry.Title.Text
Dim ss As String = entry.Metrics(0).Value
visits = ss
Next
I have the same problem and it looks like google recently shut down the feed. It is answered in another post. Issue com.google.gdata.util.ResourceNotFoundException: Not Found with Google Analytic
Please make sure you registered your project in the APIs Console and you are sending the API Key with your requests.
If that is not the issue, inspecting the inner exception will give you more details about the error. As an alternative, you can use Fiddler to capture the HTTP request and the response. The latter will include a more descriptive error message.

Resources