Apply DateTime filter for getting list messages in gmail using gmail API - timezone

I am using GMAIL API to get messages between a date range. My problem is for one of my client account the display datetime and actual received date/sent datetime differs. IS there a way to read messages in UTC time zone?
Thanks,
Haseena

There is an open issue that affects the timezone of dates in search queries. Unfortunately there is no workaround at the moment.

$newTime = strtotime('-15 day');
$after = strtotime(date('Y-m-d H:i:s', $newTime));
$opt_param = array();
$userId = 'me';
$opt_param['q'] = "after:$after";
$messagesResponse = $service->users_messages->listUsersMessages($userId, $opt_param);

Related

How to convert UTC timezone to CET timezone in graph api?

Am tried with this piece of code
var Option = new List<Option>()
{
new QueryOption("startDateTime", filterStartDate.ToLongDateString()),
new QueryOption("endDateTime", filterEndDate.ToLongDateString()),
new HeaderOption("Prefer","outlook.timezone=\"Central European Time\"")
};
but am getting the bad request error.
Can anyone help me with this?
I have 2 ideas on your scenario, the first is that, according to the official sample, you can add Prefer request header like this if you used Graph SDK.
var events = await graphClient.Me.Events
.Request()
.Header("Prefer","outlook.timezone=\"Pacific Standard Time\"")
.Select("subject,body,bodyPreview,organizer,attendees,start,end,location")
.GetAsync();
By the way, the time zone you used is Central European Time but it's not supported by graph api. Per my searching, only Central European Standard Time can be found.
In general, the timeZone property can be set to any of the time zones currently supported by Windows, as well as the additional time zones supported by the calendar API.
The correct time zone is Central Europe Standard Time not Central European Time.
If you are calling calendar view events, startDateTime and endDateTime must be represented in ISO 8601 format.
var queryOptions = new List<QueryOption>()
{
new QueryOption("startDateTime", filterStartDate.ToUniversalTime().ToString("o")),
new QueryOption("endDateTime", filterEndDate.ToUniversalTime().ToString("o"))
new HeaderOption("Prefer","outlook.timezone=\"Central Europe Standard Time\"")
};
var calendarView = await graphClient.Me.Calendar.CalendarView
.Request(queryOptions)
.GetAsync();

Microsoft graph delta query documentation clarification

I am going through documentation for Microsoft Graph https://learn.microsoft.com/en-us/graph/delta-query-events?tabs=java and found that section "The next round: sample first request" doesn't include delta query as part of request in which case the current state meaning all the events should be returned.
Also, I see that the same request has no start or end date. I am aware that this call is being made using the deltaToken received in last call. So, should start and end Date be passed while making a call where I am using deltaToken to fetch the next set of changes?
Below is the code used in Documentation(Neither deltaToken is included nor Start and End date):
IGraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
LinkedList<Option> requestOptions = new LinkedList<Option>();
requestOptions.add(new HeaderOption("Prefer", "odata.maxpagesize=2"));
IEventDeltaCollectionPage delta = graphClient.me().calendarView()
.delta()
.buildRequest( requestOptions )
.get();
Please help. Thanks in advance.
Any query parameter provided in the initial Delta query will be encoded in the Delta or skip token, this is why you don't need to pass it every time. (Start and end dates)
There seems to be an issue with this documentation page, it's never showing to use the Delta link and passing it back as a Delta token query parameter (similar to what's done with the skiptoken). I'll PR the docs tomorrow to get that fixed.

microsoft graph createreply wrong timezone

In our Angular 5 application, we are using Microsoft Graph to retrieve mail messages from a mailbox and then send a reply. For creating the reply, we use the REST API:
https://graph.microsoft.com/v1.0/me/messages/{message ID}/createReply
This creates a reply with a timezone that is UTC, but we expect it to be GMT+1. For example, in the mail body it says:
From: Melissa van Dijk
Sent: Friday, February 23, 2018 9:51:49 AM (wrong timestamp)
To: Melissa van Dijk
Subject: Meet for lunch?
We checked the settings in our Office 365 mail account and there it is specified that our local timezone is GMT+1 (Brussels, Amsterdam...).
(When replying via Outlook webmail, we get a correct timestamp).
Is this a bug or do we have to correct this timestamp ourselves? Or do we need to pass the timezone with the REST call somehow?
Thanks in advance!
I'm not sure if you can adjust the human-formatted timestamps in the HTML message body, but you can certainly use the ISO 8601 formatted timestamps in the other fields in the JSON of the response. For example, you'll find:
{
...
"sentDateTime": "2018-02-23T09:51:49Z",
...
}
While this is also in UTC (denoted by the Z), you can easily parse it by using a JavaScript Date object, or Angular's own datetime functions, or your favorite time library such as Luxon, Moment, or Date-fns. From there, displaying it in local time is trivial.

Get meetings by organizer or attendee email ID using GoToMeeting SDK

I am using .Net sdk of GoToMeeting.
I want to get meetings organized by particular organizer.
I have tried using
MeetingsApi.getHistoryMeetings but it does not return me OrganizerKey so I can not filter on particular Organizer.
Is there any way to get meeting(s) based on organizer or even by Attendee email ID by using .Net SDK?
What is the problem you are facing with MeetingsApi.getHistoryMeetings();?
why you need to filter the method, the MeetingsApi.getHistoryMeetings(accessToken,true,date1,date2); itself filtered for a particular user right?
Look on the arguments we are passing in the method?
accessToken - This token is generated as a result of successful authentication of a gotoproduct account. (In API call it can be generated using directlogin orOauth method.
true - this represents whether the meetings returned are past or not.
date1 - Start date range for the meetings.
date2 - End date range for the meetings.
below code is the sample for getting history meetings.
DateTime sdt=DateTime.Parse("07/01/2015");
DateTime edt=DateTime.Parse("07/30/2015");
List<MeetingHistory> historymeets = new System.Collections.Generic.List<MeetingHistory>();
historymeets=meeting.getHistoryMeetings(accesToken, true, sdt, edt);
foreach (var item in historymeets)
{
Console.WriteLine(item.subject);
}
try it out... The above code will store the meetings in historymeets collection object.
You can do the filter function in that collection object.
UPDATE :
List<MeetingHistory> historymeets = new System.Collections.Generic.List<MeetingHistory>();
historymeets=meeting.getHistoryMeetings(accesToken, true, sdt, edt);
List<AttendeeByMeeting> lstAttendee = new System.Collections.Generic.List<AttendeeByMeeting>();
foreach (var item in historymeets)
{
Console.WriteLine(item.meetingId);
lstAttendee=meeting.getAttendeesByMeetings(accesToken, item.meetingId);
foreach (var itemattendee in lstAttendee)
{
Console.WriteLine(itemattendee.attendeeEmail);
}
}
for comment - It is possible, but not directly because there is no api calls, which supports the meeting by attendee . the above code which i have written is for meeting by organizer . Now you have two options,
get the getHistoryMeetings, now you got the meeting details right? , then get the attendees by meeting id using getAttendeesByMeetings(), filter the two different collection objects with join using LINQ. OR
get the meetingdetails and attendees by executing two different fuinction calls, and store it in database or somewhere else, so that you can access it for doing the filter

How to get twitter server time?

So I'm trying to build a real time monitoring tool for twitter key words using tweet sharp. I'm using the search API to collect queries every 10-15 seconds. When I make the calls, I only want to collect tweets that have appeared since the pervious update.
var twitter = FluentTwitter.CreateRequest().AuthenticateAs("username", "password").Search().Query().Containing("key word").Take(1000);
var response = twitter.Request();
currentResponseDateTime= Convert.ToDateTime(response.ResponseDate);
var messages = from m in response.AsSearchResult().Statuses
where m.CreatedDate > lastUpdateDateTime
select m;
lastUpdateDateTime = currentResponseDateTime;
My issue is that the twitter server time is different from the client times by a few seconds. I looked around and tried to get the datetime I recieved the response from the Response.ResponseDate property, but it looks like that is set based on the local computer time. I.e currentResponseDateTime is a few seconds ahead of the Twitter Server time. So I end up not collecting a few of the tweets.
Does anyone know how I can get the current server time from twitter search or REST API?
Thanks
I'm not sure how you would get the local server time of the twitter service, but one approach you could take is to store the date of the most recent twitter update seen in the "lastUpdateDateTime" field. That way, you're guaranteed to get all the messages since the last one you saw, regardless of the offset of the twitter server.
var twitter = FluentTwitter.CreateRequest().AuthenticateAs("username", "password").Search().Query().Containing("key word").Take(1000);
var response = twitter.Request();
currentResponseDateTime= Convert.ToDateTime(response.ResponseDate);
var messages = from m in response.AsSearchResult().Statuses
where m.CreatedDate > lastUpdateDateTime
select m;
lastUpdateDateTime = messages.Select(m => m.CreatedDate).Max();
Another approach (and one that Twitter recommends) is to pull the Date header from their API server's response, which provides Twitter's notion of time in GMT. This assumes that you can access the server response headers, and that depends on the method you're using to access the API.
For example, hitting https://api.twitter.com/1/help/test.json
$ lynx --dump --head https://api.twitter.com/1/help/test.json
HTTP/1.0 200 OK
Date: Tue, 22 Jan 2013 13:30:36 GMT
...
Reference: how to get the twitter server time (synchronize)? on dev.twitter.com support site.
Quoting Taylor Singletary:
The current time that Twitter "thinks" it is is returned in the "Date" HTTP header of every response to an API call you make. You can also issue a simple HTTP HEAD request to GET help/test to get the header as an initial syncing step for your app.

Resources