Page Summary
-
Only users with the Admin role can create new users with access to their resource or those under it.
-
New users are created using the user.create method.
-
To create a new user, their email address must have a corresponding Google Account and the user resource must include at least one assigned user role.
If assigned the Admin role for a resource, you can create a user with access to that resource or those under it.
Users are created through the user.create
method.
A new user's email address must have a corresponding Google Account, which can be created for an existing email address . The user resource created must also include at least one assigned user role.
Here's an example of how to create a new user with standard access to an advertiser:
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'] );

