开发者

Google Calendar API - Can I get the "Privacy" field for an Event? i.e. Public/Private/Default - or is this not available

开发者 https://www.devze.com 2022-12-21 09:44 出处:网络
Re the Google Calendar API, I can\'t seem to see the Privacy\" field for an Event? i.e. Public/Private开发者_StackOverflow中文版/Default.

Re the Google Calendar API, I can't seem to see the Privacy" field for an Event? i.e. Public/Private开发者_StackOverflow中文版/Default.

Is there a way to get the "Privacy" field for an Event? i.e. Public/Private/Default - or is this not available?


You can't get "privacy" field for an Event but you have to filter (public\private) events on your query.

query = gdata.calendar.service.CalendarEventQuery('default', 'private', 'full')
feed = calendar_service.CalendarQuery(query)

The second parameter of CalendarEventQuery is visibility (private\public)

Have a look to Event feeds too.


i had the same problem as you (i want to hide private busy events), and found no solutions on the web. getVisibility() returns undefined on private and public events... i dont know why !

So this is a way to find private events, but it not return an array with 'default | private | full'

getPrivateCopy() return an object if the event is private, and return undefined if not.

So there is my code :

var private = entry.getPrivateCopy();
//if the event isn't private
if (!private) {
//doing something
}

This is not the best solution because that method doesn't remove the event from feed. If somebody have a better solution, i'm interested !


It works for me. Either changing or viewing the privacy of an event works.

CalendarEventFeed resultFeed = myService.query(myQuery, CalendarEventFeed.class);

// Goes through all events.
System.out.println("Updating events from " + startTime.toString() + " to " + endTime.toString() + ":\n");
for (int i = 0; i < resultFeed.getEntries().size(); i++) {
  // Obtains the entry.
  CalendarEventEntry entry = resultFeed.getEntries().get(i);

  // Changes the visibility to private and update the entry.
  //entry.getVisibility().setValue(Visibility.PRIVATE_VALUE);
  //entry.update();

  // Print some information in the output.
  System.out.println("- " + entry.getTitle().getPlainText() + " -- Visibility is now: " + entry.getVisibility().getValue());
}

Uncomment the lines after the "Changes the visibility to private" comment and this code will change all your events to private in your default calendar (assuming myService is a properly set up CalendarService and myQuery is a query that returns all your events).

Hope this helps, - Vítor Souza

0

精彩评论

暂无评论...
验证码 换一张
取 消