googleapis / google-api-dotnet-client

Google APIs Client Library for .NET
https://developers.google.com/api-client-library/dotnet
Apache License 2.0
1.34k stars 523 forks source link

Unable to retrieve appointment schedules using Google Calendar API? #2428

Closed mirror222 closed 1 year ago

mirror222 commented 1 year ago

Hi there,

Find the image & code below, I want to retrieve appointment schedules programmatically, but it seems not works. Can someone guide me on how to use the Google Calendar API to fetch appointment records?

using Google.Apis.Auth.OAuth2;
using Google.Apis.Calendar.v3;
using Google.Apis.Calendar.v3.Data;
using Google.Apis.Services;

GoogleCredential credential;
using (var stream = new FileStream("credentials.json", FileMode.Open, FileAccess.Read))
{
    credential = GoogleCredential.FromStream(stream)
        .CreateScoped(CalendarService.Scope.Calendar);
}

var service = new CalendarService(new BaseClientService.Initializer
{
    HttpClientInitializer = credential,
    ApplicationName = "Your Application Name",
});

// Appointment list
EventsResource.ListRequest request = service.Events.List("primary");
request.TimeMin = DateTime.Now;
request.ShowDeleted = false;
request.SingleEvents = true;
request.MaxResults = 10;
request.OrderBy = EventsResource.ListRequest.OrderByEnum.StartTime;

Events events = request.Execute();
IList<Event> items = events.Items;

if (items != null && items.Count > 0)
{
    foreach (var eventItem in items)
    {

        string appointmentSummary = eventItem.Summary;
        DateTime startTime = (DateTime)eventItem.Start.DateTime;
        DateTime endTime = (DateTime)eventItem.End.DateTime;
        //....
    }
}
jskeet commented 1 year ago

It's unclear to me at the moment where the problem lies - you've got some code, what happens when you execute that? Does it not find the events, or find them but return something unusual?

The maintainers of this repository aren't experts in all the different Google APIs that are available - only how the .NET client libraries can be used to make requests to those APIs. (We can help customers who know what their API call should look like but are having trouble with how to make that request using C#, but not with figuring out the request to start with.)

I suggest you use the list events documentation page, and in particular the "try it now" section on the right hand side, adjusting your request until it's giving you the data you expect. We can then help you construct that same request in code, or handle the responses - but we'll need more details.

mirror222 commented 1 year ago

Thank you for your response. Here are the details:

Please refer to the images below, which show two entries: one is a regular Event, and the other is an Appointment schedule. image

I tried using the "Events: list" command you mentioned earlier to retrieve them. However, I can only see the Event item and cannot access the appointment.

image

{
 "kind": "calendar#events",
 "etag": "\"p33kc7se1gv2fu0g\"",
 "summary": "support@XXX.com",
 "updated": "2023-06-15T00:51:33.185Z",
 "timeZone": "Asia/Tokyo",
 "accessRole": "owner",
 "defaultReminders": [
  {
   "method": "popup",
   "minutes": 10
  }
 ],
 "nextSyncToken": "COjD8cGHxP8CEOjD8cGHxP8CGAUgx7LpgAI=",
 "items": [
  {
   "kind": "calendar#event",
   "etag": "\"3373580586370000\"",
   "id": "6lh9jtvdfdkqmn2icaejdks4d7",
   "status": "confirmed",
   "htmlLink": "https://www.google.com/calendar/event?eid=NmxoOWp0dmRmZGtxbW4yaWNhZWpka3M0ZDcgc3VwcG9ydEBiYWNrdXBjdXRlLmNvbQ",
   "created": "2023-06-14T07:57:01.000Z",
   "updated": "2023-06-15T00:51:33.185Z",
   "summary": "My Test Event",
   "description": "THIS IS THE MEMO.",
   "creator": {
    "email": "support@XXXXX.com",
    "self": true
   },
   "organizer": {
    "email": "support@XXXX.com",
    "self": true
   },
   "start": {
    "dateTime": "2023-06-13T09:30:00+09:00",
    "timeZone": "Asia/Tokyo"
   },
   "end": {
    "dateTime": "2023-06-13T10:30:00+09:00",
    "timeZone": "Asia/Tokyo"
   },
   "iCalUID": "11h9jtvdfdkqmn2icaejdks4d7@google.com",
   "sequence": 0,
   "attendees": [
    {
     "email": "XXXX@XXX.com",
     "responseStatus": "needsAction"
    },
    {
     "email": "support@XXXXXX.com",
     "organizer": true,
     "self": true,
     "responseStatus": "accepted"
    }
   ],
   "hangoutLink": "https://meet.google.com/ajj-iwgk-mtu",
   "conferenceData": {
    "entryPoints": [
     {
      "entryPointType": "video",
      "uri": "https://meet.google.com/ajj-iwgk-mtu",
      "label": "meet.google.com/ajj-iwgk-mtu"
     },
     {
      "entryPointType": "more",
      "uri": "https://tel.meet/ajj-iwgk-mtu?pin=1260399150071",
      "pin": "1260399150071"
     },
     {
      "regionCode": "JP",
      "entryPointType": "phone",
      "uri": "tel:+81-3-4545-000",
      "label": "+81 3-4545-000",
      "pin": "3060399150071"
     }
    ],
    "conferenceSolution": {
     "key": {
      "type": "hangoutsMeet"
     },
     "name": "Google Meet",
     "iconUri": "https://fonts.gstatic.com/s/i/productlogos/meet_2020q4/v6/web-512dp/logo_meet_2020q4_color_2x_web_512dp.png"
    },
    "conferenceId": "ajj-iwgk-mtu"
   },
   "reminders": {
    "useDefault": true
   },
   "attachments": [
    {
     "fileUrl": "https://drive.google.com/open?id=22222228trx53K_s5W48Nc1mgDa",
     "title": "Help Center",
     "mimeType": "application/vnd.google-apps.site",
     "iconLink": "https://drive-thirdparty.googleusercontent.com/32/type/application/vnd.google-apps.site",
     "fileId": "12345678903iCH1nhK_s5W48Nc1mgDa"
    }   
   ],
   "eventType": "default"
  }
 ]
}

Could you please guide me on how to retrieve records of the appointment type?

jskeet commented 1 year ago

Okay, this sounds like it really is a question about how to use the API, rather than being specific to the C# client library. I'm afraid the team responsible for this repository can't provide support on every API covered by our libraries - I suggest you follow one of the routes on the Calendar API support page. I'll close this issue now, as I don't believe we'll be able to help you further, but I do wish you luck.