本文档简要介绍了如何使用 Drive API 迁移代码以获取权限
Looker Studio API 管理。对于常见的云端硬盘 API 端点,该部分会显示
相应的 Looker Studio API 代码。
文件
对于 Drive API 文件端点,Looker Studio API 只有一个等效项
端点为 Files: list 端点。
列表
API
方法
端点
云端硬盘
POST
/drive/v3/files
Looker Studio
GET
/v1/assets:search
比较:
云端硬盘
constoAuthToken='123'// This should be replaced with a valid OAuth token.fetch(`https://www.googleapis.com/drive/v3/files`,{headers:{Authorization:`Bearer ${oAuthToken}`},method:"POST",})
Looker Studio
constoAuthToken='123'// This should be replaced with a valid OAuth token.fetch(`https://datastudio.googleapis.com/v1/assets:search?assetTypes={ASSET_TYPE}`,{headers:{Authorization:`Bearer ${oAuthToken}`}})
云端硬盘和 Looker Studio 之间没有一对一的匹配关系,但端点
用于实现类似的目标。主要区别在于,云端硬盘文件可以有多个
而 Looker Studio 只有一个。
API
方法
端点
云端硬盘
GET
/drive/v3/files/fileId/permissions
Looker Studio
GET
/v1/assets/assetId/permissions
比较:
云端硬盘
以下代码列出了 Drive API 的所有权限对象。借助代码,您可以使用分页令牌(如图所示)多次调用该方法,以确保您可以查看为某个文件设置的所有权限。
constfileId='123';// This should be replaced with a valid Drive ID.constoAuthToken='123';// This should be replaced with a valid OAuth token.letnextPageToken=undefined;letpermissions=[];do{constpermissionsData=awaitfetch(`https://www.googleapis.com/drive/v3/files/${fileId}/permissions`,{headers:{Authorization:`Bearer ${oAuthToken}`}});nextPageToken=permissionsData.nextPageToken;permissions=permissions.concat(permissionsData.permissions)}while(nextPageToken!==undefined);
Looker Studio
由于 Looker Studio 资源只有一个权限对象,因此无需
因此必须考虑分页
constoAuthToken='123'// This should be replaced with a valid OAuth token.constassetId='123'// This should be replaced with a valid asset ID.fetch(`https://datastudio.googleapis.com/v1/assets/{ASSET_ID}/permissions`,{headers:{Authorization:`Bearer ${oAuthToken}`}}
在更新权限方面,Looker Studio API 和 Drive API 非常相似,
功能主要区别在于,您无法在expirationTime
Looker Studio 权限。
API
方法
端点
云端硬盘
PATCH
/drive/v3/files/fileId/permissions/permissionId
Looker Studio
PATCH
/v1/assets/assetId/permissions
比较:
云端硬盘
constfileId='123';// This should be replaced with a valid Drive ID.constoAuthToken='123';// This should be replaced with a valid OAuth token.constnewPermissionsObject={expirationTime:'...',role:'owner',// Or any other option}fetch(`https://www.googleapis.com/drive/v3/files/${fileId}/permissions/permissionId`,{headers:{Authorization:`Bearer ${oAuthToken}`},method:"PATCH",body:JSON.stringify(newPermissionsObject)})
Looker Studio
constoAuthToken='123'// This should be replaced with a valid OAuth token.constassetId='123'// This should be replaced with a valid asset ID.constnewPermissionsObject={permissions:{//...}}fetch(`https://datastudio.googleapis.com/v1/assets/${assetId}/permissions`,{headers:{Authorization:`Bearer ${oAuthToken}`},method:"PATCH",body:JSON.stringify({name:assetId,permissions:newPermissionsObject})})
[null,null,["最后更新时间 (UTC):2025-07-25。"],[[["\u003cp\u003eThis guide explains how to migrate code using the Drive API for permission management to the Looker Studio API, providing equivalent Looker Studio API code snippets for common Drive API endpoints.\u003c/p\u003e\n"],["\u003cp\u003eThe Looker Studio API has limited file management functionality compared to the Drive API, with only an equivalent endpoint for listing files (\u003ccode\u003eFiles: list\u003c/code\u003e).\u003c/p\u003e\n"],["\u003cp\u003eWhile the Drive API allows managing multiple permission objects per file, Looker Studio assets have a single, always-existing permission object, leading to different endpoint usage for permission control.\u003c/p\u003e\n"],["\u003cp\u003eDespite differences in managing permissions, both APIs offer similar functionalities for updating permissions, with the exception of setting expiration times on Looker Studio permissions.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers should use appropriate HTTP libraries for their chosen language when making calls to the Looker Studio API, as there are no dedicated client libraries available.\u003c/p\u003e\n"]]],[],null,["# Migrating from the Drive API\n\nThis document outlines how to migrate code using the Drive API for permission\nmanagement to the Looker Studio API. For common Drive API endpoints, it shows\nthe corresponding Looker Studio API code.\n| **Note:** There are no client libraries for using the Looker Studio API. To make these calls, use an appropriate HTTP library for your language.\n\nFiles\n-----\n\nFor the Drive API files endpoints, the Looker Studio API only has an equivalent\nendpoint for the `Files: list` endpoint.\n\n### List\n\n| API | Method | Endpoint |\n|---------------|--------|---------------------|\n| Drive | `POST` | `/drive/v3/files` |\n| Looker Studio | `GET` | `/v1/assets:search` |\n\nComparison:\n\n**Drive** \n\n const oAuthToken = '123' // This should be replaced with a valid OAuth token.\n fetch(`https://www.googleapis.com/drive/v3/files`, {\n headers: {\n Authorization: `Bearer ${oAuthToken}`\n },\n method: \"POST\",\n })\n\n**Looker Studio** \n\n const oAuthToken = '123' // This should be replaced with a valid OAuth token.\n fetch(`https://datastudio.googleapis.com/v1/assets:search?assetTypes={ASSET_TYPE}`, {\n headers: {\n Authorization: `Bearer ${oAuthToken}`\n }\n })\n\nSee [search assets](/looker-studio/integrate/api/reference/assets/search).\n\nPermissions\n-----------\n\n### Create, Delete, And Get\n\n| API | Method | Endpoint |\n|-------|----------|---------------------------------------------------|\n| Drive | `POST` | `/drive/v3/files/fileId/permissions` |\n| Drive | `DELETE` | `/drive/v3/files/fileId/permissions/permissionId` |\n| Drive | `GET` | `/drive/v3/files/fileId/permissions/permissionId` |\n\nThere are no corresponding endpoints in the Looker Studio API for managing\nmultiple `Permissions` objects. There is only one permissions object for a\nLooker Studio asset, and it always exists.\n\n- To remove someone from an asset, see [revoke all permissions](/looker-studio/integrate/api/reference/permissions/revokeAllPermissions)\n- To add someone to an asset, see [add members](/looker-studio/integrate/api/reference/permissions/addMembers)\n- To view a permissions object for an asset, see [get permissions](/looker-studio/integrate/api/reference/permissions/get)\n\n### List\n\nThere isn't a 1-to-1 match between Drive and Looker Studio, but the endpoints\nserve similar goals. The main difference is that a Drive file can have many\npermissions objects, and Looker Studio has exactly one.\n\n| API | Method | Endpoint |\n|---------------|--------|--------------------------------------|\n| Drive | `GET` | `/drive/v3/files/fileId/permissions` |\n| Looker Studio | `GET` | `/v1/assets/assetId/permissions` |\n\nComparison:\n\n**Drive**\n\nThis following code lists all the permissions objects for the Drive API.\nDepending on your code, you may call this method multiple times using pagination\ntokens (as shown) to ensure you can see all of the permissions that are set for\na file. \n\n const fileId = '123'; // This should be replaced with a valid Drive ID.\n const oAuthToken = '123'; // This should be replaced with a valid OAuth token.\n let nextPageToken = undefined;\n let permissions = [];\n do {\n const permissionsData = await fetch(`https://www.googleapis.com/drive/v3/files/${fileId}/permissions`, {\n headers: {\n Authorization: `Bearer ${oAuthToken}`\n }\n });\n nextPageToken = permissionsData.nextPageToken;\n permissions = permissions.concat(permissionsData.permissions)\n } while (nextPageToken !== undefined);\n\n**Looker Studio**\n\nSince there is only one permission object for a Looker Studio asset, you don't\nhave to account for pagination. \n\n const oAuthToken = '123' // This should be replaced with a valid OAuth token.\n const assetId = '123' // This should be replaced with a valid asset ID.\n fetch(`https://datastudio.googleapis.com/v1/assets/{ASSET_ID}/permissions`, {\n headers: {\n Authorization: `Bearer ${oAuthToken}`\n }\n }\n\nSee [get permissions](/looker-studio/integrate/api/reference/permissions/get).\n\nUpdate\n------\n\nFor updating permissions, the Looker Studio and Drive APIs have very similar\nfunctionality. The main difference is you cannot set an `expirationTime` on a\nLooker Studio permission.\n\n| API | Method | Endpoint |\n|---------------|---------|---------------------------------------------------|\n| Drive | `PATCH` | `/drive/v3/files/fileId/permissions/permissionId` |\n| Looker Studio | `PATCH` | `/v1/assets/assetId/permissions` |\n\nComparison:\n\n**Drive** \n\n const fileId = '123'; // This should be replaced with a valid Drive ID.\n const oAuthToken = '123'; // This should be replaced with a valid OAuth token.\n const newPermissionsObject = {\n expirationTime: '...',\n role: 'owner', // Or any other option\n }\n fetch(`https://www.googleapis.com/drive/v3/files/${fileId}/permissions/permissionId`, {\n headers: {\n Authorization: `Bearer ${oAuthToken}`\n },\n method: \"PATCH\",\n body: JSON.stringify(newPermissionsObject)\n })\n\n**Looker Studio** \n\n const oAuthToken = '123' // This should be replaced with a valid OAuth token.\n const assetId = '123' // This should be replaced with a valid asset ID.\n const newPermissionsObject = {\n permissions: {\n //...\n }\n }\n\n fetch(`https://datastudio.googleapis.com/v1/assets/${assetId}/permissions`, {\n headers: {\n Authorization: `Bearer ${oAuthToken}`\n },\n method: \"PATCH\",\n body: JSON.stringify({\n name: assetId,\n permissions: newPermissionsObject\n })\n })\n\nFor use-case specific alternatives, see:\n\n- [add members](/looker-studio/integrate/api/reference/permissions/addMembers)\n- [revoke all permissions](/looker-studio/integrate/api/reference/permissions/revokeAllPermissions)"]]