ユーザー リソースには、ユーザーの表示名や一意の ID などのユーザー固有の情報と、権限情報や割り当てられたユーザー役割の両方が含まれます。
このページでは、メールアドレスを使用してユーザー リソースを取得する方法について説明します。
フィルタされたリストからユーザーを取得する
ディスプレイ&ビデオ 360 API のユーザー リソースには、作成時にシステムによって一意の ID が割り当てられます。この ID を使用して、users.get メソッドでユーザー リソースを取得できます。ただし、ユーザーの userId がない場合は、users.list メソッドと filter パラメータを使用してユーザー リソースを取得し、メールアドレスでフィルタできます。
このメソッドを使用してユーザー リソースを取得する方法の例を次に示します。
Java
// Create a variable to store the desired user once found.UserretrievedUser=newUser();// Create the filter string for list call. Using this filter will return all// users with an email address containing the specified value.StringemailFilter=String.format("email:\"%s\"",email-address);// Configure the list request.Users.Listrequest=service.users().list();// Set the filter for the request.request.setFilter(emailFilter);// Create the response and nextPageToken variables.ListUsersResponseresponse;StringnextPageToken=null;do{// Create and execute the list request.response=request.setPageToken(nextPageToken).execute();// Check if response is empty.if(response.isEmpty()){break;}// Iterate over retrieved line items and add to total list.for(Useruser:response.getUsers()){if(user.getEmail()==email-address){retrievedUser=user;break;}}// Update the next page token.nextPageToken=response.getNextPageToken();}while(!Strings.isNullOrEmpty(nextPageToken) && retrievedUser.isEmpty());// Print user information if a user was found.if(!retrievedUser.isEmpty()){System.out.printf("User %s was found.\n",retrievedUser.getName());System.out.printf("User: %s, Display Name: %s, Email: %s\n",retrievedUser.getUserId(),retrievedUser.getDisplayName(),retrievedUser.getEmail());AssignedUserRoleuserRole;for(inti=0;i < retrievedUser.getAssignedUserRoles().size();i++){userRole=retrievedUser.getAssignedUserRoles().get(i);System.out.printf("Assigned User Role %s:\n",i+1);if(userRole.getPartnerId()!=null){System.out.printf("Partner ID: %s\n",userRole.getPartnerId());}else{System.out.printf("Advertiser ID: %s\n",userRole.getAdvertiserId());}System.out.printf("User Role: %s\n",userRole.getUserRole());}}else{System.out.printf("No user was found with email address %s",email-address);}
Python
# Create a variable to store the desired user once found.retrieved_user=None# Create the filter string for list call. Using this filter will return all# users with an email address containing the specified value.email_filter='email:"%s"'%email-address# Create the page token variable.next_page_token=''whileTrue:# Request the users list.response=service.users().list(filter=email_filter,pageToken=next_page_token).execute()# Check if the response is empty.ifnotresponse:break# Iterate over retrieved users.foruserinresponse['users']:# Break from the loop if the user is found.ifuser['email']==email-addressretrieved_user=userbreak# Break out of the loop if there is no next page or if the user has been# found.if'nextPageToken'notinresponseoruserisnotNone:break# Update the next page token.next_page_token=response['nextPageToken']# Print user information if a user was found.ifretrieved_user:print('User %s was found.'%retrieved_user['name'])print('User: %s, Display Name: %s, Email: %s'%(retrieved_user['userId'],retrieved_user['displayName'],retrieved_user['email']))forindexinrange(len(retrieved_user['assignedUserRoles'])):print('Assigned User Role %s:'%index)if'partnerId'inretrieved_user['assignedUserRoles'][0]:print('Partner ID: %s'%retrieved_user['assignedUserRoles'][0]['partnerId'])else:print('Advertiser ID: %s'%retrieved_user['assignedUserRoles'][0]['advertiserId'])print('User Role: %s'%retrieved_user['assignedUserRoles'][0]['userRole'])else:print('No user was found with email address %s'%email-address)
PHP
// Create a variable to store the desired user once found.$retrievedUser = null;// Create the filter string with the desired user email.$emailFilter = 'email:"' . email-address . '"';# Create the page token variable.$nextPageToken = '';do { // Build argument parameters for list call. $optParams = array( 'filter' => $emailFilter, 'pageToken' => $nextPageToken ); // Call the API, getting the line items with flights ending before the // given date. $response = $this->service->users->listUsers($optParams); // If no line items are returned, break loop. if (!empty($response->getUsers())) { break; } foreach ($response->getUsers() as $user) { if ($user->getEmail() == email-address) { $retrievedUser = $user; break; } } $nextPageToken = $response->getNextPageToken();} while (is_null($retrievedUser) && $nextPageToken);// Print user information if a user was found.if (!is_null($retrievedUser)) { printf( 'User %s was found.\nUser: %s, Display Name: %s, Email: %s\n', $retrievedUser->getName(), $retrievedUser->getUserId(), $retrievedUser->getDisplayName(), $retrievedUser->getEmail() ); // Print each assigned user role for user. foreach ($retrievedUser->getAssignedUserRoles() as $userRole) { print("Assigned User Role:\n"); if ($userRole->getPartnerId()) { printf("\tPartner ID: %s\n", $userRole->getPartnerId()); } else { printf("\tAdvertiser ID: %s\n", $userRole->getAdvertiserId()); } printf("\tUser Role: %s\n", $userRole->getUserRole()); }} else { printf( "No user was found with email address %s",email-address );}
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-07-25 UTC。"],[[["\u003cp\u003eThis page provides instructions for retrieving user resources using an email address instead of a user ID.\u003c/p\u003e\n"],["\u003cp\u003eUser resources include user-specific information and permissions details.\u003c/p\u003e\n"],["\u003cp\u003eThe retrieval process involves filtering by email address using the \u003ccode\u003eusers.list\u003c/code\u003e method with the \u003ccode\u003efilter\u003c/code\u003e parameter.\u003c/p\u003e\n"],["\u003cp\u003eCode samples are provided in Java, Python, and PHP demonstrating the retrieval process.\u003c/p\u003e\n"]]],[],null,["# Retrieve a user\n\nThe user resource includes both user-specific information, such as the user\ndisplay name and unique ID, as well as permissions information, or [assigned\nuser roles](/display-video/api/reference/rest/current/users#assigneduserrole).\n\nThis page describes how to retrieve a user resource using an email address.\n\nRetrieve a user from filtered list\n----------------------------------\n\nDisplay \\& Video 360 API user resources have a unique ID assigned by the system upon\ncreation. This ID can be used to retrieve a user resource through the\n[`users.get`](/display-video/api/reference/rest/current/users/get) method. However, if you do not have the\n[`userId`](/display-video/api/reference/rest/current/users#User.FIELDS.user_id) for a user, you can still retrieve the user resource using\nthe [`users.list`](/display-video/api/reference/rest/current/users/list) method with the [`filter`](/display-video/api/reference/rest/current/users/list#body.QUERY_PARAMETERS.filter)\nparameter to filter by email address.\n\nHere's an example of how to retrieve your user resource using this method: \n\n### Java\n\n```java\n// Create a variable to store the desired user once found.\nUser retrievedUser = new User();\n\n// Create the filter string for list call. Using this filter will return all\n// users with an email address containing the specified value.\nString emailFilter = String.format(\"email:\\\"%s\\\"\", email-address);\n\n// Configure the list request.\nUsers.List request =\n service\n .users()\n .list();\n\n// Set the filter for the request.\nrequest.setFilter(emailFilter);\n\n// Create the response and nextPageToken variables.\nListUsersResponse response;\nString nextPageToken = null;\n\ndo {\n // Create and execute the list request.\n response = request.setPageToken(nextPageToken).execute();\n\n // Check if response is empty.\n if (response.isEmpty()) {\n break;\n }\n\n // Iterate over retrieved line items and add to total list.\n for (User user : response.getUsers()) {\n if (user.getEmail() == email-address) {\n retrievedUser = user;\n break;\n }\n }\n\n // Update the next page token.\n nextPageToken = response.getNextPageToken();\n\n} while (!Strings.isNullOrEmpty(nextPageToken) && retrievedUser.isEmpty());\n\n// Print user information if a user was found.\nif (!retrievedUser.isEmpty()) {\n System.out.printf(\"User %s was found.\\n\", retrievedUser.getName());\n System.out.printf(\"User: %s, Display Name: %s, Email: %s\\n\",\n retrievedUser.getUserId(),\n retrievedUser.getDisplayName(),\n retrievedUser.getEmail());\n\n AssignedUserRole userRole;\n\n for (int i = 0; i \u003c retrievedUser.getAssignedUserRoles().size(); i++) {\n userRole = retrievedUser.getAssignedUserRoles().get(i);\n\n System.out.printf(\"Assigned User Role %s:\\n\", i+1);\n\n if (userRole.getPartnerId() != null) {\n System.out.printf(\"Partner ID: %s\\n\", userRole.getPartnerId());\n } else {\n System.out.printf(\"Advertiser ID: %s\\n\", userRole.getAdvertiserId());\n }\n\n System.out.printf(\"User Role: %s\\n\", userRole.getUserRole());\n }\n} else {\n System.out.printf(\"No user was found with email address %s\", email-address);\n}\n```\n\n### Python\n\n```python\n# Create a variable to store the desired user once found.\nretrieved_user = None\n\n# Create the filter string for list call. Using this filter will return all\n# users with an email address containing the specified value.\nemail_filter = 'email:\"%s\"' % email-address\n\n# Create the page token variable.\nnext_page_token = ''\n\nwhile True:\n # Request the users list.\n response = service.users().list(\n filter=email_filter,\n pageToken=next_page_token\n ).execute()\n\n # Check if the response is empty.\n if not response:\n break\n\n # Iterate over retrieved users.\n for user in response['users']:\n # Break from the loop if the user is found.\n if user['email'] == email-address\n retrieved_user = user\n break\n\n # Break out of the loop if there is no next page or if the user has been\n # found.\n if 'nextPageToken' not in response or user is not None:\n break\n\n # Update the next page token.\n next_page_token = response['nextPageToken']\n\n# Print user information if a user was found.\nif retrieved_user:\n print('User %s was found.' % retrieved_user['name'])\n\n print('User: %s, Display Name: %s, Email: %s'\n % (retrieved_user['userId'],\n retrieved_user['displayName'],\n retrieved_user['email']))\n\n for index in range(len(retrieved_user['assignedUserRoles'])):\n print('Assigned User Role %s:' % index)\n\n if 'partnerId' in retrieved_user['assignedUserRoles'][0]:\n print('Partner ID: %s' % retrieved_user['assignedUserRoles'][0]['partnerId'])\n else:\n print('Advertiser ID: %s' %\n retrieved_user['assignedUserRoles'][0]['advertiserId'])\n\n print('User Role: %s' % retrieved_user['assignedUserRoles'][0]['userRole'])\nelse:\n print('No user was found with email address %s' % email-address)\n```\n\n### PHP\n\n```php\n// Create a variable to store the desired user once found.\n$retrievedUser = null;\n\n// Create the filter string with the desired user email.\n$emailFilter = 'email:\"' . \u003cvar translate=\"no\"\u003eemail-address\u003c/var\u003e . '\"';\n\n# Create the page token variable.\n$nextPageToken = '';\n\ndo {\n // Build argument parameters for list call.\n $optParams = array(\n 'filter' =\u003e $emailFilter,\n 'pageToken' =\u003e $nextPageToken\n );\n\n // Call the API, getting the line items with flights ending before the\n // given date.\n $response = $this-\u003eservice-\u003eusers-\u003elistUsers($optParams);\n\n // If no line items are returned, break loop.\n if (!empty($response-\u003egetUsers())) {\n break;\n }\n\n foreach ($response-\u003egetUsers() as $user) {\n if ($user-\u003egetEmail() == \u003cvar translate=\"no\"\u003eemail-address\u003c/var\u003e) {\n $retrievedUser = $user;\n break;\n }\n }\n\n $nextPageToken = $response-\u003egetNextPageToken();\n} while (is_null($retrievedUser) && $nextPageToken);\n\n// Print user information if a user was found.\nif (!is_null($retrievedUser)) {\n printf(\n 'User %s was found.\\nUser: %s, Display Name: %s, Email: %s\\n',\n $retrievedUser-\u003egetName(),\n $retrievedUser-\u003egetUserId(),\n $retrievedUser-\u003egetDisplayName(),\n $retrievedUser-\u003egetEmail()\n );\n\n // Print each assigned user role for user.\n foreach ($retrievedUser-\u003egetAssignedUserRoles() as $userRole) {\n print(\"Assigned User Role:\\n\");\n if ($userRole-\u003egetPartnerId()) {\n printf(\"\\tPartner ID: %s\\n\", $userRole-\u003egetPartnerId());\n } else {\n printf(\"\\tAdvertiser ID: %s\\n\", $userRole-\u003egetAdvertiserId());\n }\n printf(\"\\tUser Role: %s\\n\", $userRole-\u003egetUserRole());\n }\n} else {\n printf(\n \"No user was found with email address %s\",\n \u003cvar translate=\"no\"\u003eemail-address\u003c/var\u003e\n );\n}\n```"]]