Chrome 管理應用程式 / Extension Details API 的程式碼範例

如需 API 功能的總覽,請造訪 Chrome Management App Details API

下方顯示的所有要求都使用下列變數:

  • $TOKEN:OAuth 2 權杖
  • $CUSTOMER - 客戶 ID 或常值my_customer

取得 Chrome 應用程式 / 擴充功能的詳細資料

如要查看特定 Chrome 應用程式的詳細資料,請使用 /apps/chrome/{app_id}@{app_version} 端點。

要求

  curl -X GET \
  -H "Authorization: Bearer $TOKEN" \
  "https://chromemanagement.googleapis.com/v1/customers/$CUSTOMER/apps/chrome/abcdefghijklmnopqrstuvwxyzabcdef@1.2.3"

回應

{
    "name": "customers/<customer>/apps/chrome/abcdefghijklmnopqrstuvwxyzabcdef@1.2.3",
    "displayName": "Sample Google Chrome Extension",
    "description": "A sample Google Chrome extension.",
    "revisionId": "1.2.3",
    "type": "CHROME",
    "iconUri": "https://sample.chrome.extension.google.com/icon.png",
    "detailUri": "https://chrome.google.com/webstore/detail/abcdefghijklmnopqrstuvwxyzabcdef",
    "firstPublishTime": "2010-10-10T10:10:10.123456Z",
    "latestPublishTime": "2020-10-10T10:10:10.123456Z",
    "publisher": "sample.com",
    "homepageUri": "http://sample.chrome.extension.google.com/home",
    "reviewNumber": "10000",
    "reviewRating": 4.5,
    "chromeAppInfo": {
        "supportEnabled": false,
        "minUserCount": 6000000,
        "permissions": [
            {
                "type": "content_security_policy",
                "documentationUri": "https://developer.chrome.com/extensions/contentSecurityPolicy",
                "accessUserData": false
            },
            {
                "type": "contextmenus",
                "documentationUri": "https://developer.chrome.com/extensions/contextMenus",
                "accessUserData": false
            },
        ],
        "siteAccess": [
            {
                "hostMatch": "<all_urls>"
            }
        ],
        "isTheme": false,
        "googleOwned": true,
        "isCwsHosted": true
    }
}

取得 Android 應用程式的詳細資料

如要查看特定 Android 應用程式的詳細資料,請使用 /apps/android/{app_id}@{app_version} 端點。

要求

  curl -X GET \
  -H "Authorization: Bearer $TOKEN" \
  "https://chromemanagement.googleapis.com/v1/customers/$CUSTOMER/apps/android/com.google.android.sample@1.2.3"

回應

{
    "name": "customers/<customer>/apps/android/com.google.android.sample@1.2.3",
    "displayName": "Sample Android App",
    "description": "A sample Android app.",
    "appId": "com.google.android.sample",
    "revisionId": "1.2.3",
    "type": "ANDROID",
    "iconUri": "https://sample.android.app.google.com/icon.png",
    "detailUri": "https://play.google.com/store/apps/details?id=com.google.android.sample",
    "firstPublishTime": "2010-10-10T10:10:10.123456Z",
    "latestPublishTime": "2020-10-10T10:10:10.123456Z",
    "publisher": "Google LLC",
    "isPaidApp": true,
    "homepageUri": "http://sample.android.app.google.com/home",
    "privacyPolicyUri": "http://sample.android.app.google.com/privacy",
    "reviewNumber": "10000",
    "reviewRating": 4.5,
    "androidAppInfo": {
        "permissions": [
            {
                "type": "android.permission.CAMERA"
            },
        ]
    }
}

取得漸進式網頁應用程式的詳細資料

如要查看特定 Prgoressive 網頁應用程式的詳細資料,請使用 /apps/web/{app_id} 端點。請注意,應用程式 ID 是經過網址編碼的應用程式首頁。

要求

  curl -X GET \
  -H "Authorization: Bearer $TOKEN" \
  "https://chromemanagement.googleapis.com/v1/customers/$CUSTOMER/apps/web/http%3A%2F%2Fsample.web.app.google.com%2F"

回應

{
    "name": "customers/<customer>/apps/web/http%3A%2F%sample.web.app.google.com%2F",
    "displayName": "sample.web.app.google.com",
    "description": "A sample Progressive Web App.",
    "appId": "http://sample.web.app.google.com/",
    "type": "WEB",
    "iconUri": "http://sample.web.app.google.com/icon.png"
}

列出要求的 Chrome 擴充功能

如要列出要求的 Chrome 應用程式,請使用 /apps:countChromeAppRequests 端點。

要求

  curl -X GET \
  -H "Authorization: Bearer $TOKEN" \
  "https://chromemanagement.googleapis.com/v1/customers/$CUSTOMER/apps:countChromeAppRequests"

回應

{
  "requestedApps": [
    {
      "appId": "abcdefghijklmnopqrstuvwxyzabcdef",
      "displayName": "Sample Google Chrome Extension",
      "appDetails": "customers/<customer>/apps/chrome/abcdefghijklmnopqrstuvwxyzabcdef",
      "iconUri": "https://sample.chrome.extension.google.com/icon.png",
      "detailUri": "https://chrome.google.com/webstore/detail/abcdefghijklmnopqrstuvwxyzabcdef",
      "requestCount": "1",
      "latestRequestTime": "2020-10-10T10:10:10.123456Z"
    },
  ],
  "totalSize": 1
}

針對擴充功能要求採取行動

為了讓使用者的應用程式要求採取適當行動,您需要使用 Chrome Policy API。請按照設定指南的說明取得 API 存取權。然後,您可以向該 API 發出要求,以執行各種操作。您可以按這裡查看提出應用程式相關要求的範例。以下是您可以針對應用程式要求執行的常見動作。

核准機構單位下使用者/裝置手動安裝的擴充功能要求

curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d '{
        requests: [{
                policyTargetKey: {
                        targetResource: "orgunits/04fatzly4jbjho9",
                        additionalTargetKeys: {"app_id": "chrome:abcdefghijklmnopqrstuvwxyzabcdef"}
                        },
                policyValue: {
                        policySchema: "chrome.users.apps.InstallType",
                        value: {appInstallType: "ALLOWED"}
                        },
                updateMask: {paths: "appInstallType"}
                }]
      }' \
  "https://chromepolicy.googleapis.com/v1/customers/$CUSTOMER/policies/orgunits:batchModify"

成功的回應應該空白:

{}

拒絕機構單位下所有使用者/裝置的擴充功能要求

curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d '{
        requests: [{
                policyTargetKey: {
                        targetResource: "orgunits/04fatzly4jbjho9",
                        additionalTargetKeys: {"app_id": "chrome:abcdefghijklmnopqrstuvwxyzabcdef"}
                        },
                policyValue: {
                        policySchema: "chrome.users.apps.InstallType",
                        value: {appInstallType: "BLOCKED"}
                        },
                updateMask: {paths: "appInstallType"}
                }]
      }' \
  "https://chromepolicy.googleapis.com/v1/customers/$CUSTOMER/policies/orgunits:batchModify"

成功的回應應該空白:

{}

為機構單位中的所有使用者/裝置強制安裝擴充功能

curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d '{
        requests: [{
                policyTargetKey: {
                        targetResource: "orgunits/04fatzly4jbjho9",
                        additionalTargetKeys: {"app_id": "chrome:abcdefghijklmnopqrstuvwxyzabcdef"}
                        },
                policyValue: {
                        policySchema: "chrome.users.apps.InstallType",
                        value: {appInstallType: "FORCED"}
                        },
                updateMask: {paths: "appInstallType"}
                }]
      }' \
  "https://chromepolicy.googleapis.com/v1/customers/$CUSTOMER/policies/orgunits:batchModify"

成功的回應應該空白:

{}