新增使用者

如果您已取得資源的管理員角色,即可建立使用者 或具備該資源的存取權

您可透過 user.create 方法建立使用者。

新使用者的電子郵件地址必須擁有對應的 Google 帳戶,這是 以現有的電子郵件地址建立。該使用者 已建立的資源也必須包含至少一個指定的使用者角色。

以下舉例說明如何建立具有標準存取權的新使用者 廣告客戶:

Java

// Create the user structure.
User user = new User();
user.setEmail(email-address);
user.setDisplayName(display-name);

// Create the assigned user role structure.
AssignedUserRole assignedUserRole = new AssignedUserRole();
assignedUserRole.setAdvertiserId(advertiser-id);
assignedUserRole.setUserRole("STANDARD");

// Add assigned user role list to the user.
user.setAssignedUserRoles(ImmutableList.of(assignedUserRole));

// Configure the create request.
Users.Create request = service.users().create(user);

// Create the user.
User response = request.execute();

// Display the user.
System.out.printf("User %s was created with email %s.",
    response.getName(),
    response.getEmail());

Python

# Create a user object.
user_obj = {
    'email': email-address,
    'displayName': display-name,
    'assignedUserRoles': [
        {
            'advertiserId': advertiser-id,
            'userRole': 'STANDARD'
        }
    ]
}

# Build request.
request = service.users().create(
    body=user_obj
)

# Execute request.
response = request.execute()

# Display the new user.
print('User %s was created with email %s.'
      % (response['name'], response['email']))

PHP

// Create the user structure.
$user = new Google_Service_DisplayVideo_User();
$user->setEmail(email-address);
$user->setDisplayName(display-name);

// Create the assigned user role structure.
$assignedUserRole = new Google_Service_DisplayVideo_AssignedUserRole();
$assignedUserRole->setAdvertiserId(advertiser-id);
$assignedUserRole->setUserRole('STANDARD');

// Add assigned user role list to the user.
$user->setAssignedUserRoles(array($assignedUserRole));

// Call the API, creating the user with the assigned user role.
$result = $this->service->users->create($user);

// Display the user.
printf(
    'User %s was created with email %s.\n',
    $result['name'],
    $result['email']
);