تفویض اختیار در سراسر دامنه Google Workspace را انجام دهید
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
Cloud Search Query API مستلزم آن است که تماسهای API با استفاده از اطلاعات کاربری OAuth متعلق به یک کاربر دارای مجوز در دامنه شما مجاز باشد. بهطور پیشفرض، حسابهای سرویس، که برای دسترسی به APIهای نمایهسازی و پیکربندی استفاده میشوند، نمیتوانند برای تماسهای API پرسوجو استفاده شوند، زیرا آنها کاربران دامنه با مجوزهای Cloud Search یا Google Workspace نیستند. اگر میخواهید هنگام احراز هویت تماسهای API پرسوجو از یک حساب سرویس استفاده کنید، یک سرپرست دامنه میتواند به حساب دامنه دسترسی به دادههای کاربر اجازه دهد - این به عنوان تفویض اختیار در سطح دامنه شناخته میشود. یک حساب سرویس با اختیارات تفویض شده میتواند هویت هر کاربری را جعل کند، از جمله کاربرانی که به جستجوی ابری دسترسی دارند.
اختیارات گسترده دامنه را به حساب سرویس خود تفویض کنید
برای دسترسی به دادههای کاربر در دامنه Google Workspace، حساب سرویسی که ایجاد کردهاید باید توسط یک سرپرست فوقالعاده برای دامنه دسترسی داشته باشد. برای اطلاعات بیشتر درباره تفویض اختیار در سطح دامنه، به کنترل دسترسی API Google Workspace با تفویض اختیار در سطح دامنه مراجعه کنید.
برای واگذاری اختیارات دامنه به یک حساب سرویس:
از کنسول مدیریت دامنه خود، به menuمنوی اصلی > امنیت > کنترل دسترسی و داده > کنترلهای API بروید.
در صفحه نمایندگی گسترده دامنه ، مدیریت نمایندگی گسترده دامنه را انتخاب کنید.
روی افزودن جدید کلیک کنید.
در قسمت Client ID ، شناسه مشتری به دست آمده از مراحل ایجاد حساب سرویس در بالا را وارد کنید.
در قسمت OAuth Scopes ، فهرستی از محدوده های مورد نیاز برای برنامه خود را وارد کنید. از دامنه https://www.googleapis.com/auth/cloud_search.query برای برنامه های جستجو با استفاده از Query API استفاده کنید.
روی تأیید کلیک کنید.
حساب سرویس شما اکنون به Cloud Search Query API دسترسی گستردهای دارد و میتواند هویت هر کاربر دامنه شما را در این محدوده جعل کند. شما آماده هستید تا یک شیء سرویس Cloud Search API مجاز از طرف کاربران دامنه خود را نمونه برداری کنید.
یک شی سرویس Cloud Search API را نمونهسازی کنید
این بخش نشان میدهد که چگونه میتوان یک شی سرویس Cloud Search API را نمونهسازی کرد و سپس به آن اجازه داد تا با استفاده از OAuth 2.0 و اعتبارنامه حساب سرویس شما درخواستهای API را برای انجام تفویض اختیار در دامنه Google Workspace ارسال کند. نمونهها اطلاعات حساب سرویس را از فایل کلید خصوصی با فرمت JSON میخوانند.
جاوا
importjava.util.Collections;importjava.io.FileInputStream;importcom.google.api.client.googleapis.auth.oauth2.GoogleCredential;importcom.google.api.client.http.HttpTransport;importcom.google.api.client.json.JsonFactory;importcom.google.api.services.cloudsearch.v1.CloudSearch;importcom.google.api.services.cloudsearch.v1.CloudSearchScopes;.../** Path to the Service Account's Private Key file */privatestaticfinalStringSERVICE_ACCOUNT_FILE_PATH="/path/to/key.json";/** * Build and return a Cloud Search service object authorized with the service * account that acts on behalf of the given user. * * @param userEmail The email of the user to impersonate. Needs permissions to access Cloud Search. * @return CloudSearch service object that is ready to make requests. */publicstaticCloudSearchgetCloudSearchAPIService(StringuserEmail)throwsFileNotFoundException,IOException{FileInputStreamcredsFile=newFileInputStream(SERVICE_ACCOUNT_FILE_PATH);GoogleCredentialinit=GoogleCredential.fromStream(credsFile);HttpTransporthttpTransport=init.getTransport();JsonFactoryjsonFactory=init.getJsonFactory();GoogleCredentialcreds=newGoogleCredential.Builder().setTransport(httpTransport).setJsonFactory(jsonFactory).setServiceAccountId(init.getServiceAccountId()).setServiceAccountPrivateKey(init.getServiceAccountPrivateKey()).setServiceAccountScopes(Collections.singleton(CloudSearchScopes.CLOUD_SEARCH_QUERY)).setServiceAccountUser(userEmail).build();CloudSearchservice=newCloudSearch.Builder(httpTransport,jsonFactory,creds).build();returnservice;}
پایتون
fromgoogle.oauth2importservice_accountfromgoogleapiclient.discoveryimportbuild# Path to the Service Account's Private Key fileSERVICE_ACCOUNT_FILE_PATH="/path/to/key.json"defcreate_query_api_service(user_email):"""Build and return a CloudSearch service object authorized with the service account that acts on behalf of the given user. Args: user_email: The email of the user to impersonate. Needs permissions to access Cloud Search. Returns: Cloud Search Query API service object that is ready to make requests. """credentials=service_account.Credentials.from_service_account_file(SERVICE_ACCOUNT_FILE_PATH,scopes=['https://www.googleapis.com/auth/cloud_search.query'])delegated_credentials=credentials.with_subject(user_email)returnbuild("cloudsearch","v1",credentials=delegated_credentials)
تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی."],[],[],null,["# Perform Google Workspace domain-wide delegation of authority\n\nThe Cloud Search Query API requires that API calls are authorized using OAuth\ncredentials belonging to a licensed user in your domain. By default, service\naccounts, which are used to access the indexing and configuration APIs, cannot\nbe used for query API calls because they are not domain users with Cloud Search\nor Google Workspace licenses. If you wish to use a service account when\nauthenticating query API calls, a domain administrator can grant the account\ndomain-wide access to user data --- this is known as\n*domain-wide delegation of authority*. A service account with delegated\nauthority can impersonate any user, including users with access to Cloud Search.\n\nCreate the service account and credentials\n------------------------------------------\n\nIf you do not yet have service account credentials, refer to\n[Create service account credentials](/workspace/cloud-search/docs/guides/project-setup#create_service_account_credentials).\n\nDelegate domain-wide authority to your service account\n------------------------------------------------------\n\nTo access user data on a Google Workspace domain, the service account that\nyou created needs to be granted access by a super administrator for the domain.\nFor more information about domain-wide delegation, see\n[Control Google Workspace API access with domain-wide delegation](https://support.google.com/a/answer/162106).\n\nTo delegate domain-wide authority to a service account:\n\n1. From your domain's [Admin console](http://admin.google.com), go to **Main menu** menu \\\u003e **Security** \\\u003e **Access and data control** \\\u003e **API controls**.\n2. In the **Domain wide delegation** pane, select **Manage Domain Wide\n Delegation**.\n\n3. Click **Add new**.\n\n4. In the **Client ID** field, enter the client ID obtained from the\n service account creation steps above.\n\n5. In the **OAuth Scopes** field, enter a comma-delimited list of the scopes\n required for your application. Use the scope\n `https://www.googleapis.com/auth/cloud_search.query` for search applications\n using the Query API.\n\n6. Click **Authorize**.\n\nYour service account now has domain-wide access to the Cloud Search Query API,\nand can impersonate any user of your domain in this scope. You are ready to\ninstantiate an authorized Cloud Search API service object on behalf of your\ndomain's users.\n| **Note:** To access the Query API, your service must impersonate a user with access to Cloud Search. Additionally, the user must have logged in at least once and accepted the Google Workspace Terms of Service. The Query API will return results with ACLs according to the permissions of the impersonated user.\n\nInstantiate a Cloud Search API service object\n---------------------------------------------\n\nThis section shows how to instantiate a Cloud Search API service object and then\nauthorize it to make API requests using OAuth 2.0 and your service account's\ncredentials to perform Google Workspace domain-wide delegation. The examples\nread the service account's information from the JSON-formatted private key file. \n\n### Java\n\n import java.util.Collections;\n import java.io.FileInputStream;\n import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;\n import com.google.api.client.http.HttpTransport;\n import com.google.api.client.json.JsonFactory;\n import com.google.api.services.cloudsearch.v1.CloudSearch;\n import com.google.api.services.cloudsearch.v1.CloudSearchScopes;\n ...\n\n /** Path to the Service Account's Private Key file */\n private static final String SERVICE_ACCOUNT_FILE_PATH = \"/path/to/key.json\";\n\n /**\n * Build and return a Cloud Search service object authorized with the service\n * account that acts on behalf of the given user.\n *\n * @param userEmail The email of the user to impersonate. Needs permissions to access Cloud Search.\n * @return CloudSearch service object that is ready to make requests.\n */\n public static CloudSearch getCloudSearchAPIService(String userEmail)\n throws FileNotFoundException, IOException {\n\n FileInputStream credsFile = new FileInputStream(SERVICE_ACCOUNT_FILE_PATH);\n\n GoogleCredential init = GoogleCredential.fromStream(credsFile);\n\n HttpTransport httpTransport = init.getTransport();\n JsonFactory jsonFactory = init.getJsonFactory();\n\n GoogleCredential creds = new GoogleCredential.Builder()\n .setTransport(httpTransport)\n .setJsonFactory(jsonFactory)\n .setServiceAccountId(init.getServiceAccountId())\n .setServiceAccountPrivateKey(init.getServiceAccountPrivateKey())\n .setServiceAccountScopes(Collections.singleton(CloudSearchScopes.CLOUD_SEARCH_QUERY))\n .setServiceAccountUser(userEmail)\n .build();\n\n CloudSearch service = new CloudSearch.Builder(httpTransport, jsonFactory, creds).build();\n\n return service;\n }\n\n### Python\n\n from google.oauth2 import service_account\n from googleapiclient.discovery import build\n\n # Path to the Service Account's Private Key file\n SERVICE_ACCOUNT_FILE_PATH = \"/path/to/key.json\"\n\n def create_query_api_service(user_email):\n \"\"\"Build and return a CloudSearch service object authorized with the service\n account that acts on behalf of the given user.\n\n Args:\n user_email: The email of the user to impersonate. Needs permissions to access Cloud Search.\n Returns:\n Cloud Search Query API service object that is ready to make requests.\n \"\"\"\n credentials = service_account.Credentials.from_service_account_file(\n SERVICE_ACCOUNT_FILE_PATH,\n scopes=['https://www.googleapis.com/auth/cloud_search.query'])\n\n delegated_credentials = credentials.with_subject(user_email)\n\n return build(\"cloudsearch\", \"v1\", credentials=delegated_credentials)"]]