Chrome Management Profiles API 的程式碼範例

如要瞭解 API 功能,請參閱「Chrome Management Profiles API」。

這個頁面顯示的所有要求都會使用下列變數:

  • $TOKEN - OAuth 2.0 權杖
  • $CUSTOMER - 客戶 ID 或字面值 my_customer

列出受管理的設定檔

如要列出受管理設定檔,請使用 /profiles 端點。您可以使用 pageSizepageToken 參數控制結果的分頁。使用 orderBy 指定結果的順序。指定 filter 進一步縮小結果範圍。您可以使用 fields 查詢參數指定讀取遮罩,請注意,如果讀取遮罩排除 reportingData 欄位,列出設定檔的效率就會提高。

要求

  curl -X GET \
  -H "Authorization: Bearer $TOKEN" \
  "https://chromemanagement.googleapis.com/v1/customers/$CUSTOMER/profiles?pageSize=2&orderBy=lastPolicySyncTime&filter=osPlatformType=WINDOWS+AND+affiliationState=PROFILE_ONLY&fields=chromeBrowserProfiles.name,chromeBrowserProfiles.profileId,chromeBrowserProfiles.profilePermanentId,chromeBrowserProfiles.displayName,chromeBrowserProfiles.userEmail,chromeBrowserProfiles.lastActivityTime,chromeBrowserProfiles.osPlatformType,chromeBrowserProfiles.policyCount,chromeBrowserProfiles.reportingData,chromeBrowserProfiles.identityProvider,chromeBrowserProfiles.affiliationState"

回應

{
  "chromeBrowserProfiles": [
    {
      "name": "customers/<customerId>/profiles/<profilePermanentId1>",
      "profileId": "<profileId1>",
      "profilePermanentId": "<profilePermanentId1>",
      "displayName": "My profile 1",
      "userEmail": "<userEmail1>",
      "lastActivityTime": "2024-04-23T22:05:44.214362Z",
      "osPlatformType": "WINDOWS",
      "policyCount": "2",
      "reportingData": [
        {
          "browserExecutablePath": "<executablePath1>",
          "profilePath": "<profilePath1>",
          "extensionData":[
            {
              "extensionId": "ghbmnnjooekpmoecnnnilnnbdlolhkhi",
              "version": "1.76.1",
              "name": "Google Docs Offline",
              "extensionType": "EXTENSION",
              "homepageUri": "https://chrome.google.com/webstore/detail/ghbmnnjooekpmoecnnnilnnbdlolhkhi",
              "installationType": "NORMAL",
              "isDisabled": true,
              "isWebstoreExtension": true,
              "manifestVersion": 3
            }
          ],
          "policyData":[
            {
              "source": "MACHINE_PLATFORM",
              "name": "AutoSelectCertificateForUrls",
              "value": "\"********\""
            },
            {
              "source": "USER_CLOUD",
              "name": "BrowserThemeColor",
              "value": "\"#00FF00\""
            }
          ]
        }
      ],
      "identityProvider": "GOOGLE_IDENTITY_PROVIDER",
      "affiliationState": "PROFILE_ONLY"
    },
    {
      "name": "customers/<customerId>/profiles/<profilePermanentId2>",
      "profileId": "<profileId2>",
      "profilePermanentId": "<profilePermanentId2>",
      "displayName": "My profile 2",
      "userEmail": "<userEmail2>",
      "lastActivityTime": "2024-04-23T22:05:44.214362Z",
      "osPlatformType": "WINDOWS",
      "policyCount": "1",
      "reportingData": [
        {
          "browserExecutablePath": "<executablePath2>",
          "profilePath": "<profilePath2>",
          "policyData":[
            {
              "source": "USER_CLOUD",
              "name": "CloudProfileReportingEnabled",
              "value": "true"
            }
          ]
        }
      ],
      "identityProvider": "GOOGLE_IDENTITY_PROVIDER",
      "affiliationState": "PROFILE_ONLY"
    }
  ],
  "next_page_token": "<nextPageToken>",
  "total_size": "120"
}

擷取受管理的設定檔

如要擷取代管設定檔,請使用 /profiles/{profile_permanent_id} 端點。讀取遮罩可使用 fields 參數指定。

要求

  curl -X GET \
  -H "Authorization: Bearer $TOKEN" \
  "https://chromemanagement.googleapis.com/v1/customers/$CUSTOMER/profiles/<profilePermanentId1>?fields=chromeBrowserProfiles.name,chromeBrowserProfiles.profileId,chromeBrowserProfiles.profilePermanentId,chromeBrowserProfiles.displayName,chromeBrowserProfiles.userEmail,chromeBrowserProfiles.lastActivityTime,chromeBrowserProfiles.osPlatformType,chromeBrowserProfiles.policyCount,chromeBrowserProfiles.reportingData,chromeBrowserProfiles.identityProvider,chromeBrowserProfiles.affiliationState"

回應

{
  "name": "customers/<customerId>/profiles/<profilePermanentId1>",
  "profileId": "<profileId1>",
  "profilePermanentId": "<profilePermanentId1>",
  "displayName": "My profile 1",
  "userEmail": "<userEmail1>",
  "lastActivityTime": "2024-04-23T22:05:44.214362Z",
  "osPlatformType": "WINDOWS",
  "policyCount": "2",
  "reportingData": [
    {
      "browserExecutablePath": "<executablePath1>",
      "profilePath": "<profilePath1>",
      "extensionData":[
        {
          "extensionId": "ghbmnnjooekpmoecnnnilnnbdlolhkhi",
          "version": "1.76.1",
          "name": "Google Docs Offline",
          "extensionType": "EXTENSION",
          "homepageUri": "https://chrome.google.com/webstore/detail/ghbmnnjooekpmoecnnnilnnbdlolhkhi",
          "installationType": "NORMAL",
          "isDisabled": true,
          "isWebstoreExtension": true,
          "manifestVersion": 3
        }
      ],
      "policyData":[
        {
          "source": "MACHINE_PLATFORM",
          "name": "AutoSelectCertificateForUrls",
          "value": "\"********\""
        },
        {
          "source": "USER_CLOUD",
          "name": "BrowserThemeColor",
          "value": "\"#00FF00\""
        }
      ]
    }
  ],
  "identityProvider": "GOOGLE_IDENTITY_PROVIDER",
  "affiliationState": "PROFILE_ONLY"
}

刪除受管理設定檔收集的資料

如要刪除從受管理設定檔收集的資料,請使用 /profiles/{profile_permanent_id} 端點。

要求

  curl -X DELETE \
  -H "Authorization: Bearer $TOKEN" \
  "https://chromemanagement.googleapis.com/v1/customers/$CUSTOMER/profiles/<profilePermanentId1>"

對受管理設定檔發出遠端指令

如要對受管理設定檔發出遠端指令,請使用 /profiles/{profile_permanent_id}/commands/ 端點。

要求

  curl -X POST \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  --data '{"command_type":"clearBrowsingData", "payload":{clearCache:true, clearCookies:true}}' \
  "https://chromemanagement.googleapis.com/v1/customers/$CUSTOMER/profiles/<profilePermanentId1>/commands"

回應

{
  "name": "customers/<customerId>/profiles/<profilePermanentId1>/commands/<commandId1>",
  "commandType": "clear_browsing_data",
  "payload": {
    "clear_cache": true,
    "clear_cookies": true
  },
  "commandState": "PENDING",
  "issueTime": "2025-04-05T16:43:37.668Z",
  "validDuration": "86400s"
}

擷取對受管理設定檔發出的遠端指令

如要擷取發送至受管理設定檔的遠端指令,請使用 /profiles/{profile_permanent_id}/commands/{command_id} 端點。

要求

  curl -X GET \
  -H "Authorization: Bearer $TOKEN" \
  "https://chromemanagement.googleapis.com/v1/customers/$CUSTOMER/profiles/<profilePermanentId1>/commands/<commandId1>"

回應

{
  "name": "customers/<customerId>/profiles/<profilePermanentId1>/commands/<commandId1>",
  "commandType": "clear_browsing_data",
  "payload": {
    "clear_cache": true,
    "clear_cookies": true
  },
  "commandState": "EXECUTED_BY_CLIENT",
  "commandResult": {
    "resultType": "SUCCESS",
    "clientExecutionTime": "2025-04-05T14:01:51.082Z"
  },
  "issueTime": "2025-04-05T14:01:49.914Z",
  "validDuration": "86400s"
}

列出發布給受管理設定檔的遠端指令

如要列出發給受管理設定檔的遠端指令,請使用 /profiles/{profile_permanent_id}/commands 端點。

要求

  curl -X GET \
  -H "Authorization: Bearer $TOKEN" \
  "https://chromemanagement.googleapis.com/v1/customers/$CUSTOMER/profiles/<profilePermanentId1>/commands?pageSize=2"

回應

{
  "chromeBrowserProfileCommands": [
    {
      "name": "customers/<customerId>/profiles/<profilePermanentId1>/commands/<commandId1>",
      "commandType": "clear_browsing_data",
      "payload": {
        "clear_cache": true,
        "clear_cookies": true
      },
      "commandState": "EXECUTED_BY_CLIENT",
      "commandResult": {
        "resultType": "SUCCESS",
        "clientExecutionTime": "2025-04-05T14:01:51.082Z"
      },
      "issueTime": "2025-04-05T14:01:49.914Z",
      "validDuration": "86400s"
    },
    {
      "name": "customers/<customerId>/profiles/<profilePermanentId1>/commands/<commandId2>",
      "commandType": "clear_browsing_data",
      "payload": {
        "clear_cache": true,
        "clear_cookies": false
      },
      "commandState": "EXECUTED_BY_CLIENT",
      "commandResult": {
        "resultType": "SUCCESS",
        "clientExecutionTime": "2025-04-05T14:02:59.981Z"
      },
      "issueTime": "2025-04-05T14:02:59.192Z",
      "validDuration": "86400s"
    }
  ],
  "nextPageToken": "<nextPageToken>",
  "totalSize": "10"
}