ตัวอย่างโค้ดสําหรับ Chrome Management Profiles API

ไปที่ Chrome Management Profiles API เพื่อดูภาพรวมของฟีเจอร์ API

คำขอทั้งหมดที่แสดงในหน้านี้ใช้ตัวแปรต่อไปนี้

  • $TOKEN - โทเค็น OAuth 2.0
  • $CUSTOMER - รหัสของลูกค้าหรือค่าคงที่ my_customer

แสดงรายการโปรไฟล์ที่มีการจัดการ

หากต้องการแสดงโปรไฟล์ที่จัดการ ให้ใช้/profilesปลายทาง คุณสามารถควบคุมการแบ่งหน้าของผลลัพธ์ได้โดยใช้พารามิเตอร์ pageSize และ pageToken ใช้ 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"
}