생성 시 사용자에게 할당된 사용자 역할이 하나 이상 있어야 합니다. 그러나 새 광고주가 생성되거나 조직이 여러 파트너로 확장되거나, 새로운 관련 리소스를 포함하도록 액세스 권한을 업데이트해야 합니다
사용자의 역할은
users.bulkEditAssignedUserRoles
메서드
한 번의 작업으로 사용자 역할을 삭제하고 추가할 수 있습니다. 이렇게 하면
리소스에 대한 사용자의 액세스 수준입니다.
다음은 할당된 사용자 역할을 수정하는 방법의 예입니다. 기존 사용자의 경우:
자바
// Retrieve the existing user. User user = service.users().get(user-id).execute(); // Create the bulk edit request structure. BulkEditAssignedUserRolesRequest bulkEditRequest = new BulkEditAssignedUserRolesRequest(); // Build list of user roles to add. ArrayList<AssignedUserRole> addedUserRoles = new ArrayList<AssignedUserRole>(); // Add the user role for the new advertiser and the new user role // for the existing advertiser to assign to the user. addedUserRoles.add(new AssignedUserRole() .setAdvertiserId(new-advertiser-id) .setUserRole("STANDARD")); addedUserRoles.add(new AssignedUserRole() .setAdvertiserId(existing-advertiser-id) .setUserRole("READ_ONLY")); // Add list of user roles to add to the request. bulkEditRequest.setCreatedAssignedUserRoles(addedUserRoles); // Build list of user role IDs to delete. ArrayList<String> deletedUserRoles = new ArrayList<String>(); // Create assigned user role ID to check for. String existingAssignedUserRoleId = String.format( "advertiser-%d", existing-advertiser-id ); // Check the existing user roles. If the user has an existing user role // for the existing advertiser, add it to the list of roles to be deleted. // Users cannot have multiple roles for a single resource. for (AssignedUserRole userRole: user.getAssignedUserRoles()) { if (userRole.getAssignedUserRoleId() == existingAssignedUserRoleId) { deletedUserRoles.add(existingAssignedUserRoleId); } } // Add list of user roles to delete to the request. bulkEditRequest.setDeletedAssignedUserRoles(deletedUserRoles); // Build and execute the bulk edit request. BulkEditAssignedUserRolesResponse response = service.users() .bulkEditAssignedUserRoles( user-id, bulkEditRequest ).execute(); // Check if response is empty. // If not, iterate over created AssignedUserRoles. if (response.isEmpty()) { System.out.print("Bulk edit request created no new AssignedUserRoles."); } else { for (AssignedUserRole assignedRole : response.getCreatedAssignedUserRoles()) { System.out.printf("AssignedUserRole %s was created.\n", assignedRole.getAssignedUserRoleId()); } }
Python
# Retrieve the existing user. user = service.users().get(userId=user-id).execute() # Add the user role for the new advertiser and the new user role # for the existing advertiser to assign to the user. added_user_roles = [ { 'advertiser_id': new-advertiser-id, 'user_role': 'STANDARD' }, { 'advertiser_id': existing-advertiser-id, 'user_role': 'READ_ONLY' } ] # Create empty deleted user role list to add to if necessary. deleted_user_roles = [] # Check the existing user roles. If the user has an existing user role # for the existing advertiser, add it to the list of roles to be deleted. # Users cannot have multiple roles for a single resource. for role in user['assignedUserRoles']: if role['assignedUserRoleId'] == ("advertiser-%s" % existing-advertiser-id): deleted_user_roles.append(role['assignedUserRoleId']) # Create the bulk edit request. bulk_edit_user_roles_request = { 'deletedAssignedUserRoles': deleted_user_roles, 'createdAssignedUserRoles': added_user_roles } # Edit the assigned user roles. response = service.users().bulkEditAssignedUserRoles( userId=user-id, body=bulk_edit_user_roles_request ).execute() # Check if response is empty. # If not, iterate over and display new assigned targeting options. if not response: print("Bulk edit request created no new AssignedUserRoles.") else: for assigned_user_role in response['createdAssignedUserRoles']: print("AssignedUserRole %s was created.\n" % assigned_user_role['assignedUserRoleId'])
PHP
// Call the API, retrieving the existing user. $user = $this->service->users->get(user-id); // Create an array for user roles to add. $addedUserRoles = array(); // Create new user role for new advertiser. $newAdvertiserUserRole = new Google_Service_DisplayVideo_AssignedUserRole(); $newAdvertiserUserRole->setAdvertiserId(new-advertiser-id); $newAdvertiserUserRole->setUserRole('STANDARD'); $addedUserRoles[] = $newAdvertiserUserRole; // Create new user role for existing advertiser. $existingAdvertiserUserRole = new Google_Service_DisplayVideo_AssignedUserRole(); $existingAdvertiserUserRole->setAdvertiserId( existing-advertiser-id ); $existingAdvertiserUserRole->setUserRole('READ_ONLY'); $addedUserRoles[] = $existingAdvertiserUserRole; // Create an array for user roles to delete. $deletedUserRoles = array(); // Add user role to delete list if it is being replaced by a new user role. foreach ($user->getAssignedUserRoles() as $role) { if ($role->getAdvertiserId() == existing-advertiser-id) { $deletedUserRoles[] = $role->getAssignedUserRoleId(); } } // Create the bulk edit request. $bulkEditUserRolesRequest = new Google_Service_DisplayVideo_BulkEditAssignedUserRolesRequest(); $bulkEditUserRolesRequest->setCreatedAssignedUserRoles($addedUserRoles); $bulkEditUserRolesRequest->setDeletedAssignedUserRoles($deletedUserRoles); // Call the API, editing the assigned user roles for the given user. $response = $this->service->users->bulkEditAssignedUserRoles( user-id, $bulkEditUserRolesRequest ); // Print created assigned user roles. if (!empty($response->getCreatedAssignedUserRoles())) { foreach ($response->getCreatedAssignedUserRoles() as $role) { printf( 'AssignedUserRole %s was created.\n', $role['assignedUserRoleId'] ); } } else { print('Bulk edit request created no new AssignedUserRoles.'); }