Acl: insert

建立存取權控管規則。 立即試用查看範例

要求

HTTP 要求

POST https://www.googleapis.com/calendar/v3/calendars/calendarId/acl

參數

參數名稱 說明
路徑參數
calendarId string 日曆 ID。如要擷取日曆 ID,請呼叫 calendarList.list 方法。如要存取目前登入使用者的主要日曆,請使用「primary」字詞。
選用的查詢參數
sendNotifications boolean 是否傳送日曆共用設定變更的通知。選用設定。預設值為 True。

授權

此要求需要具有下列範圍的授權:

範圍
https://www.googleapis.com/auth/calendar

詳情請參閱「驗證與授權」網頁。

要求主體

在要求主體中,提供具有以下屬性的 Acl 資源

屬性名稱 說明 附註
必要屬性
role string 指派給範圍的角色。可能的值包括:
  • none」- 無存取權。
  • freeBusyReader」- 提供有空/忙碌資訊的讀取權限,
  • reader」- 提供日曆的讀取權限,擁有讀取者存取權的使用者可以查看私人活動,但活動詳細資料會隱藏。
  • writer」- 提供日曆的讀取及寫入權限,私人活動會向具備寫入者的使用者顯示,並提供活動詳細資料。
  • owner」- 提供日曆的擁有權。這個角色具備寫入者角色的所有權限,並能查看和操控 ACL。
可寫入
scope object 這個 ACL 規則授予日曆存取權的程度。
scope.type string 範圍類型。可能的值包括:
  • default」- 公開範圍。這是預設值。
  • user」- 將範圍限制在單一使用者。
  • group」- 將範圍限制在群組內。
  • domain」- 將範圍限制在一個網域內。
注意:授予「default」或公開範圍的權限,適用於任何已驗證或未驗證的使用者。
選用屬性
scope.value string 使用者/群組的電子郵件地址,或網域名稱 (視範圍類型而定)。「default」類型省略。 可寫入

回應

如果成功,這個方法會在回應主體中傳回 Acl 資源

範例

注意:這個方法適用的程式語言眾多,我們只在此提供部分程式碼範例,完整的支援語言清單請參閱用戶端程式庫頁面

Java

使用 Java 用戶端程式庫

import com.google.api.services.calendar.Calendar;
import com.google.api.services.calendar.model.AclRule;

// ...

// Initialize Calendar service with valid OAuth credentials
Calendar service = new Calendar.Builder(httpTransport, jsonFactory, credentials)
    .setApplicationName("applicationName").build();

// Create access rule with associated scope
AclRule rule = new AclRule();
Scope scope = new Scope();
scope.setType("scopeType").setValue("scopeValue");
rule.setScope(scope).setRole("role");

// Insert new access rule
AclRule createdRule = service.acl().insert('primary', rule).execute();
System.out.println(createdRule.getId());

Python

使用 Python 用戶端程式庫

rule = {
    'scope': {
        'type': 'scopeType',
        'value': 'scopeEmail',
    },
    'role': 'role'
}

created_rule = service.acl().insert(calendarId='primary', body=rule).execute()

print created_rule['id']

PHP

使用 PHP 用戶端程式庫

$rule = new Google_Service_Calendar_AclRule();
$scope = new Google_Service_Calendar_AclRuleScope();

$scope->setType("scopeType");
$scope->setValue("scopeValue");
$rule->setScope($scope);
$rule->setRole("role");

$createdRule = $service->acl->insert('primary', $rule);
echo $createdRule->getId();

小茹

使用 Ruby 用戶端程式庫

rule = Google::Apis::CalendarV3::AclRule.new(
  scope: {
    type: 'scopeType',
    value: 'scopeEmail',
  },
  role: 'role'
)
result = client.insert_acl('primary', rule)
print result.id

試試看!

使用下方的 APIs Explorer,針對即時資料呼叫這個方法,看看會有什麼結果。