创建用户

如果针对某项资源分配了管理员角色,您可以创建用户 以及该资源下的任何资源的访问权限

用户是通过 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']
);