首页 > 解决方案 > 为什么 .event.set("fieldName", ObjectValue) 不在 Google Calendar API android 中存储任何数据?

问题描述

我成功集成了 Google Calendar API。我可以做 CRUD。但是现在由于一些要求,我想在从 android 应用程序创建时向每个事件发送一些唯一的 id。为此,我发现一种称为.set()this 的方法是键值对。

 Event event = new Event()
                    .set("appointment_id", 55475)
                    .setSummary(summary)
                    .setLocation(location)
                    .setDescription(des);

但是在获取时,我得到了所有数据,除了event.get("appointment_id")

为什么,即使它也在设置。[如果我在执行这样的插入之前在这里做: evetn.get("appointment_id"),我得到了价值,因为这是在本地我阻塞]

我也通过调试进行了检查。见下文:

在此处输入图像描述

但是,当我从 Google 日历中获取所有事件时,我没有得到:

List<Event> items = events.getItems();

标签: androidgoogle-calendar-api

解决方案


You are using the set method, but this is just an override of the com.google.api.client.json.GenericJson class, I believe this will only add this key-value to the final JSON which will be ignored by the API (as it is not an expected field).

Sincerely I don't know what is the point on creating a custom id when there is one directly integrated in calendar.

If you take a look at the insert method you can see that there is one field called id:

Opaque identifier of the event. When creating new single or recurring events, you can specify their IDs. Provided IDs must follow these rules:

  • characters allowed in the ID are those used in base32hex encoding, i.e. lowercase letters a-v and digits 0-9, see section 3.1.2 in RFC2938

  • the length of the ID must be between 5 and 1024 characters

  • the ID must be unique per calendar

Also in the same description for the field:

If you do not specify an ID, it will be automatically generated by the server.

My point being that if you need unique ID for events in calendar there is a built in method that will create them for you. And even if you need to supply your own id's you can do so informing this field.

Let me suggest you the official guide on event creation in which there is a more detailed view on the option you can take creating an Event.

Also look at the documentation for setId as this is the method you should be using instead of set.


Example:

Event event = new Event()
                    .setId("55475") // This has to be type String
                    .setSummary(summary)
                    .setLocation(location)
                    .setDescription(des);

推荐阅读