ব্যবহারকারীর অ্যাক্সেস পরিবর্তন করুন

তৈরি করার পরে, একজন ব্যবহারকারীর কমপক্ষে একটি নির্দিষ্ট ব্যবহারকারীর ভূমিকা থাকতে হবে। যাইহোক, যেহেতু নতুন বিজ্ঞাপনদাতা তৈরি করা হয় বা সংস্থাগুলি একাধিক অংশীদারের কাছে প্রসারিত হয়, নতুন প্রাসঙ্গিক সংস্থানগুলি অন্তর্ভুক্ত করার জন্য ব্যবহারকারীদের অ্যাক্সেস আপডেট করতে হবে৷

ব্যবহারকারীর ভূমিকা অবশ্যই 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());
  }
}

পাইথন

# 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'])

পিএইচপি

// 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.');
}