问题
I am having trouble figuring out how to add a calendar to all of a domain's users' CalendarList.
So far I can successfully create the Calendar and create a domain wide ACL but I don't know how to insert the calendar into domain users' lists.
Using the ruby client API it looks something like this:
client = Google::APIClient.new
service = client.discovered_api("calendar", "v3")
calendar_response = JSON.parse(client.execute(:api_method => service.calendars.insert,
:body => JSON.dump({"summary" => "events"}),
:headers => { "Content-Type" => "application/json" }).response.body)
rule = {
"scope" => {
"type" => "domain",
"value" => domain,
},
"role" => "writer"
}
acl_result = client.execute(:api_method => service.acl.insert,
:parameters => { "calendarId" => calendar_response["id"] },
:body => JSON.dump(rule),
:headers => { "Content-Type" => "application/json" })
This all works fine. It creates the calendar and it is shared with everyone in the domain. What I can't figure out is how to explicitly added it to the users' list of Calendars.
To add to the single authed user's calendar list would look like this:
list_params = {
"calendarId" => calendar_response["id"],
"hidden" => false,
"selected" => true
}
calendar_list_result = client.execute(:api_method => service.calendar_list.insert,
:body => JSON.dump(list_params),
:headers => { "Content-Type" => "application/json" })
Questions:
- If I am authenticated as a domain admin, can I create
CalendarListitem for all users? - If so, can it be done with a single command or do I need to make a call with every user id?
- If I need to do a command for each user, how do I get the user ids?
回答1:
If I am authenticated as a domain admin, can I create CalendarList item for all users? No you can't :(.
If so, can it be done with a single command or do I need to make a call with every user id? You have to make a call for each user id.
If I need to do a command for each user, how do I get the user ids? To retrieve the user id you first must list all the users in the domain with the Admin SDK API, https://developers.google.com/admin-sdk/directory/v1/guides/manage-users#get_all_domain_users , then for each INSERT command in the calendar you change the user id, for the email address.
来源:https://stackoverflow.com/questions/15146146/how-do-you-add-a-google-calendar-to-all-users-for-a-domain