Drive API からの移行

このドキュメントでは、権限管理のために Drive API を使用するコードを Looker Studio API に移行する方法について説明します。一般的な Drive API エンドポイントについては、対応する Looker Studio API コードが表示されています。

ファイル

Drive API ファイルのエンドポイントの場合、Looker Studio API には Files: list エンドポイントの同等のエンドポイントのみがあります。

リスト

API メソッド エンドポイント
Google ドライブ POST /drive/v3/files
Looker Studio GET /v1/assets:search

比較:

ドライブ

const oAuthToken = '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

const oAuthToken = '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}`
  }
})

アセットの検索をご覧ください。

権限

作成、削除、取得

API メソッド エンドポイント
Google ドライブ POST /drive/v3/files/fileId/permissions
Google ドライブ DELETE /drive/v3/files/fileId/permissions/permissionId
Google ドライブ GET /drive/v3/files/fileId/permissions/permissionId

Looker Studio API には、複数の Permissions オブジェクトの管理に対応するエンドポイントはありません。Looker Studio アセットには、権限オブジェクトが 1 つだけ存在し、常に存在します。

リスト

ドライブと Looker Studio が 1 対 1 で対応するわけではありませんが、エンドポイントの用途はほぼ同じです。主な違いは、ドライブ ファイルには多数の権限オブジェクトがあるのに対して、Looker Studio には 1 つだけ権限がある点です。

API メソッド エンドポイント
Google ドライブ GET /drive/v3/files/fileId/permissions
Looker Studio GET /v1/assets/assetId/permissions

比較:

ドライブ

次のコードは、Drive API のすべての権限オブジェクトを一覧表示します。 コードによっては、ファイルに設定されているすべての権限を表示するために、ページ設定トークンを使用してこのメソッドを複数回呼び出さなければならない場合もあります(以下を参照)。

const fileId = '123'; // This should be replaced with a valid Drive ID.
const oAuthToken = '123'; // This should be replaced with a valid OAuth token.
let nextPageToken = undefined;
let permissions = [];
do {
  const permissionsData = await fetch(`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 アセットには権限オブジェクトが 1 つしかないため、ページネーションを考慮する必要はありません。

const oAuthToken = '123' // This should be replaced with a valid OAuth token.
const assetId = '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 によく似た機能があります。主な違いは、Looker Studio の権限に expirationTime を設定できない点です。

API メソッド エンドポイント
Google ドライブ PATCH /drive/v3/files/fileId/permissions/permissionId
Looker Studio PATCH /v1/assets/assetId/permissions

比較:

ドライブ

const fileId = '123'; // This should be replaced with a valid Drive ID.
const oAuthToken = '123'; // This should be replaced with a valid OAuth token.
const newPermissionsObject = {
  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

const oAuthToken = '123' // This should be replaced with a valid OAuth token.
const assetId = '123' // This should be replaced with a valid asset ID.
const newPermissionsObject = {
  permissions: {
    //...
  }
}

fetch(`https://datastudio.googleapis.com/v1/assets/${assetId}/permissions`, {
  headers: {
    Authorization: `Bearer ${oAuthToken}`
  },
  method: "PATCH",
  body: JSON.stringify({
    name: assetId,
    permissions: newPermissionsObject
  })
})

それぞれのユースケースでの代替手段については、以下をご覧ください。