Un utente Amministratore può recuperare qualsiasi utente Display & Video 360 con accesso agli stessi partner o ai relativi inserzionisti. Un utente recuperato conterrà solo l'accesso condiviso. Recupera tutti gli utenti accessibili con una richiesta list.
Ecco come recuperare un utente con un indirizzo email noto:
Java
// Provide the email address of the user to retrieve. String emailAddress = user-email-address; // Filter for list to store the built filters. String filter = "email:\"" + emailAddress + "\""; // Configure the list request. Users.List request = service.users().list().setFilter(filter); // Create the response and nextPageToken variables. ListUsersResponse response; String nextPageToken = null; boolean userRetrieved = false; do { // Create and execute the list request. response = request.setPageToken(nextPageToken).execute(); // Check if response is empty. if (response.isEmpty()) { System.out.print("List request returned no Users"); break; } // Iterate over retrieved users. for (User user : response.getUsers()) { // If the correct user is found, print information about the user. if (emailAddress.equals(user.getEmail())) { System.out.println("Retrieved the following user with the requested email address:"); System.out.printf( "User ID: %s, Display name: %s, Email: %s%n", user.getUserId(), user.getDisplayName(), user.getEmail()); // Iterate over and print user's assigned user roles. for (AssignedUserRole retrievedRole : user.getAssignedUserRoles()) { if (retrievedRole.getPartnerId() != null) { System.out.printf( "\tPartner ID: %s, Role: %s%n", retrievedRole.getPartnerId(), retrievedRole.getUserRole()); } else if (retrievedRole.getAdvertiserId() != null) { System.out.printf( "\tAdvertiser ID: %s, Role: %s%n", retrievedRole.getAdvertiserId(), retrievedRole.getUserRole()); } } userRetrieved = true; break; } } // Update the next page token. nextPageToken = response.getNextPageToken(); } while (!Strings.isNullOrEmpty(nextPageToken)); if (!userRetrieved) { System.out.printf("No user with email address %s found.", emailAddress); }
Python
# Provide the email address of the user to retrieve. email_address = user-email-address # Build filter string for list request. list_filter = f'email:"{email_address}"' # Create the page token variable. next_page_token = "" # Create the variable to store the retrieved user. retrieved_user = None while True: # Assign page token. request = service.users().list( filter=list_filter, pageToken=next_page_token ) # Execute list request. response = request.execute() # Check if response is empty. if not response: break # Look for user with email address. for user in response["users"]: if user["email"] == email_address: retrieved_user = user break # Check if there is a following list page. if "nextPageToken" in response: next_page_token = response["nextPageToken"] else: break # Print result of user retrieval. if retrieved_user is None: print(f"No user was found with the following email address: {email_address}") else: print( "Retrieved the following user with the requested email address: " f"{retrieved_user}" )
PHP
// Provide the email address of the user to retrieve. $emailAddress = user-email-address; $response = null; $nextPageToken = null; // Build full filter string out of filter list. $filter = 'email:"' . $emailAddress . '"'; $userRetrieved = false; do { // Build list request parameters. $optParams = array( 'filter' => $filter, 'pageToken' => $nextPageToken ); // Call the API, retrieving a page of accessible users matching the // given filter values. try { $response = $this ->service ->users ->listUsers( $optParams ); } catch (\Exception $e) { $this->renderError($e); return; } $retrievedUsers = $response->getUsers(); if (empty($retrievedUsers)) { print '<p>List request returned no users.</p>'; } // Review retrieved user resources. foreach ($retrievedUsers as $user) { if ($user->getEmail() == $emailAddress) { $userRetrieved = true; print '<p>Retrieved the following user with the requested email address:</p>'; printf('<p>User ID: %s, Display name: %s, Email: %s</p><p>' . 'Assigned User Roles:</p><ul>', $user['userId'], $user['displayName'], $user['email'] ); // Iterate over and print user's assigned user roles. foreach ($user->getAssignedUserRoles() as $userRole) { if (isset($userRole['partnerId'])) { printf( '<li>Partner ID: %s, User Role: %s</li>', $userRole->getPartnerId(), $userRole->getUserRole() ); } else if (isset($userRole['advertiserId'])) { printf( '<li>Advertiser ID: %s, User Role: %s</li>', $userRole->getAdvertiserId(), $userRole->getUserRole() ); } } print '</ul>'; } } // Update the next page token. $nextPageToken = $response->getNextPageToken(); } while (!empty($nextPageToken)); if (!$userRetrieved) { printf('<p>No user with email address %s found.</p>', $emailAddress); }