יצירת משתמש חדש

יוצרים משתמש חדש עם גישה מתאימה באמצעות בקשת create.

כך יוצרים משתמש חדש עם תפקידי משתמש רגילים עבור קבוצה של מפרסמים:

Java

// Provide the email address of the user to create.
String emailAddress = user-email-address;

// Provide the display name of the user to create.
String displayName = user-display-name;

// Provide the IDs of the advertisers to give the new user Standard access to.
List<Long> advertiserIds = advertiser-ids;

// Instantiate and build list of assigned user roles for the new user.
List<AssignedUserRole> userRoles = new ArrayList<>();

for (Long id : advertiserIds) {
  userRoles.add(new AssignedUserRole().setAdvertiserId(id).setUserRole("STANDARD"));
}

// Add the assigned user roles to the user.
User user =
    new User()
        .setEmail(emailAddress)
        .setDisplayName(displayName)
        .setAssignedUserRoles(userRoles);

// Create the user.
User response = service.users().create(user).execute();

// Display the new user.
System.out.printf("User was created with ID %s.", response.getUserId());

Python

# Provide the email address of the user to create.
email_address = user-email-address

# Provide the display name of the user to create.
user_display_name = user-display-name

# Provide the IDs of the advertisers to give the new user Standard access to.
advertiser_ids = advertiser-ids

# Build the assigned user roles for the new user.
user_roles = []
for id in advertiser_ids:
    user_roles.append({"advertiserId": id, "userRole": "STANDARD"})

# Build the user object.
user_obj = {
    "email": email_address,
    "displayName": user_display_name,
    "assignedUserRoles": user_roles,
}

# Create the user.
user_response = service.users().create(body=user_obj).execute()

# Print the resulting user ID.
print(f'User was created with ID {user_response["userId"]}.')

PHP

// Provide the email address of the user to create.
$emailAddress = user-email-address;

// Provide the display name of the user to create.
$displayName = user-display-name;

// Provide the IDs of the advertisers to give the new user Standard access to.
$advertiserIds = advertiser-ids;

// Create the user object.
$user = new Google_Service_DisplayVideo_User();
$user->setEmail($emailAddress);
$user->setDisplayName($displayName);

// Build the assigned user roles for the new user.
$assignedUserRoles = array();
foreach ($advertiserIds as $id) {
    $newRole = new Google_Service_DisplayVideo_AssignedUserRole();
    $newRole->setAdvertiserId($id);
    $newRole->setUserRole('STANDARD');
    $assignedUserRoles[] = $newRole;
}

// Set the assigned user roles for the user object.
$user->setAssignedUserRoles($assignedUserRoles);

// Call the API, creating the user.
try {
    $result = $this->service->users->create($user);
} catch (\Exception $e) {
    $this->renderError($e);
    return;
}

// Display the created user.
printf('<p>User was created with ID.</p>', $result['userId']);