- OAuth2のトークンを取得する際に
tenant
を指定する*1のだが、これはOneDriveのURLのhttps://XXXXX-my.sharepoint.com/
のところに入るテナント名とは別で、common
かorganizations
かconsumers
を指定するとある。common
を指定しているドキュメント*2を参考にしてみたら以下のAADSTS50194エラーが返ってきたのでorganizations
を指定するよう変更した。AADSTS50194: Application 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'(ApplicationName) is not configured as a multi-tenant application. Usage of the /common endpoint is not supported for such applications created after '10/15/2018'. Use a tenant-specific endpoint or configure the application to be multi-tenant.
- APIのパスとファイルのパスと操作のパスをコロンで区切る。たとえば自分自身のOneDriveの
/path/to/folder
というフォルダ以下で、パスに03
を含むファイルやフォルダを検索したい場合はhttps://graph.microsoft.com/v1.0/me/drive/root:/path/to/folder:/search(q='03')
となる。このへんの考えかたがAPIドキュメントの概要のページ*3とかに全然書かれていない。 - APIのドキュメントに
GET /me/drive/items/{item-id}
など{item-id}
というメタ構文が出てくる場合がある*4。アイテムにIDベースでアドレス指定でアクセスできる*5とドキュメントには記載があるが、APIで取得したJSONの中にあるid
をこの{item-id}
に入れてもアクセスできなかった。結局パスベースでアクセスすることにした。 /FolderA/FolderB/Foobar.jpg
というファイルを作りたい場合、特に前準備なしで/FolderA/FolderB/Foobar.jpg
というパスでアップロードすればよい。前もって/FolderA/FolderB
というフォルダを作る必要はない。ファイルのアップロードが成功したら/FolderA/FolderB
というフォルダが勝手に作られる。- ファイルをアップロードすることなしに複数階層のフォルダを一気に作りたい場合は
PATCH
メソッドでリクエストを送ればいいみたい*6。ただ、手元で試したところ単発では成功したがスクリプト中で実行しようとすると失敗した(なぜだろう?)。
*1:https://docs.microsoft.com/en-us/graph/auth-v2-user
*2:https://docs.microsoft.com/ja-jp/onedrive/developer/rest-api/getting-started/graph-oauth?view=odsp-graph-online
*3:https://docs.microsoft.com/ja-jp/graph/api/resources/onedrive?view=graph-rest-1.0
*4:https://docs.microsoft.com/ja-jp/onedrive/developer/rest-api/api/driveitem_get?view=odsp-graph-online
*5:https://docs.microsoft.com/ja-jp/onedrive/developer/rest-api/concepts/addressing-driveitems?view=odsp-graph-online