[[["わかりやすい","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-03-26 UTC。"],[],[],null,["# Make requests in the Google Drive Activity API\n\nThis guide explains how to make requests in the Google Drive Activity API using the\n[`activity.query`](/workspace/drive/activity/v2/reference/rest/v2/activity/query) method.\n\nQuery key\n---------\n\nThere are 2 ways to request activity: by Google Drive item, or for everything\nunderneath a folder hierarchy.\n\n- `itemName`: The format for this key is \"items/ITEM_ID\". Typically this is a\n file in Drive. If you specify a folder for this key, it shows activity\n for the folder such as when it was created or renamed.\n\n- `ancestorName`: The format for this key is \"items/ITEM_ID\", and the\n response includes activity on all items in the subtree below this\n folder.\n\nWhen no key is set, it defaults to using the `ancestorName` of \"items/root\" and\nshows activity for all items in your Drive.\n\nPagination\n----------\n\nThe `pageSize` field allows you to request an approximate number of activities\nto return in each response. The actual count of returned activities will vary,\nso your app should handle arbitrary quantities in the response.\n\nPage sizes are limited. If your app needs many activities, make multiple\nrequests using pagination instead of setting a large value for `pageSize`.\nSpecifically, if there might be more activity to fetch than what's included in\nthe response, then the response will also contain a `nextPageToken`. To retrieve\nmore results, repeat the same request but add a `pageToken` field with the value\nof `nextPageToken` from the prior response.\n\nConsolidation\n-------------\n\n[`Action`](/workspace/drive/activity/v2/reference/rest/v2/activity/action) objects are often grouped and returned within a single\n[`DriveActivity`](/workspace/drive/activity/v2/reference/rest/v2/activity/driveactivity) resource. Some `Action` groupings occur spontaneously, such as moving an\nitem into a shared folder triggering a permission change.\n\nYou can also specify a\n[`ConsolidationStrategy`](/workspace/drive/activity/v2/reference/rest/v2/activity/query#consolidationstrategy)\n(sometimes called aggregation or batching) in the request. This enables\nother groupings of related `Action` objects, such as several actors editing one\nitem, or one [`Actor`](/workspace/drive/activity/v2/reference/rest/v2/activity/actor) moving multiple files into a new Drive folder.\n\nWhile an individual `Action` has one `Actor` and one [`Target`](/workspace/drive/activity/v2/reference/rest/v2/activity/target), after grouping,\nthe resulting `DriveActivity` can have multiple actors and multiple targets.\nEven after grouping, however, there's always a \"primary\" action that's\neither representative, or the most important, of all actions in the\n`DriveActivity` resource, depending on the requested consolidation strategy.\n\nAs a result, whether or not consolidation is turned on, it might be sufficient for\nmany clients to view only the top-level contents of a `DriveActivity` resource (such as\nthe collective actors and targets within the `primaryActionDetail`) and ignore\nthe detailed actions in the response.\n\nFilters\n-------\n\nYou can restrict the actions that might be returned in the `DriveActivity`\nresource by constructing a `filter` string in the `activity.query` request. There's\n2 supported fields: `time` and `detail.action_detail_case`.\n\n### Filter by time\n\nTo restrict actions by time range, specify the field name `time` with numerical\noperators on date values, joined by an optional \"AND\". Use milliseconds since Jan 1, 1970 or the\n[RFC 3339](https://www.rfc-editor.org/rfc/rfc3339) format, such as:\n\n- `time \u003e 1452409200000 AND time \u003c= 1492812924310`\n- `time \u003e= \"2016-01-10T01:02:03-05:00\"`\n\n### Filter by type\n\nTo restrict by action type, apply the field name `detail.action_detail_case` with\nthe \"has\" operator (`:`). Use either a singular value or a list of allowed action\ntypes enclosed in parentheses, separated by a space. To find a list of action\ntypes, review the [`ActionDetail`](/workspace/drive/activity/v2/reference/rest/v2/activity/actiondetail) objects.\n\nTo exclude an action type from the response,\nprepend a hyphen (`-`) to the beginning of the filter string.\n\nHere's some action type examples:\n\n- `detail.action_detail_case:RENAME`\n- `detail.action_detail_case:(CREATE RESTORE)`\n- `-detail.action_detail_case:MOVE`\n\n### Combinations\n\nThese filtering conditions can be combined within a single `filter` string, such as:\n\n- `detail.action_detail_case:(CREATE EDIT RESTORE) time \u003e 1452409200000`\n\nExample requests\n----------------\n\n#### Request the 10 most recent activities for a Drive item:\n\n {\n \"itemName\": \"items/\u003cvar translate=\"no\"\u003eITEM_ID\u003c/var\u003e\",\n \"pageSize\": 10\n }\n\n#### Request consolidated activities for every Drive item below an ancestor folder:\n\n {\n \"ancestorName\": \"items/\u003cvar translate=\"no\"\u003eITEM_ID\u003c/var\u003e\",\n \"consolidationStrategy\": {\n \"legacy\": {}\n }\n }\n\n#### Request all `MOVE` and `RENAME` actions on a Drive item:\n\n {\n \"itemName\": \"items/\u003cvar translate=\"no\"\u003eITEM_ID\u003c/var\u003e\",\n \"filter\": \"detail.action_detail_case:(MOVE RENAME)\"\n }\n\n#### Request all activity since January 1, 2018 EST:\n\n {\n \"ancestorName\": \"items/root\",\n \"filter\": \"time \u003e= \\\"2018-01-01T00:00:00-05:00\\\"\"\n }\n\n#### Request all activity, except `EDIT` actions, during June 2017 UTC:\n\n {\n \"ancestorName\": \"items/root\",\n \"filter\": \"time \u003e= \\\"2018-06-01T00:00:00Z\\\" time \u003c \\\"2018-07-01T00:00:00Z\\\" -detail.action_detail_case:EDIT\"\n }"]]