2025-09-10 04:45:09 +09:00

36 lines
1.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# OneDraiveに連携する方法
MSAL(認証) + requests(HTTP)のみです。
これでMicrosoft GraphのOneDrive APIを直接叩けます
## 事前準備(無料)
* アカウント
- Microsoft アカウント(個人 OneDrive)
- Microsoft Entra ID(旧Azure ADOneDrive for Business)。
- どちらでも Graph 経由で同じコードが使えます。
* アプリ登録(Azure Portal)
* https://azure.microsoft.com/ja-jp/get-started/azure-portal
* Azure Portal → App registrations → New registration
* サポートするアカウント種別は簡単のため “common” 相当(個人/組織どちらもOK)を選ぶと便利
* リダイレクトURIは不要(後述のデバイスコードフローならクライアントIDだけでOK)
* Authentication で Mobile and desktop flows(Public client) を有効化(Device Code Flow用)。
* App registrationsで選択する
* 左メニューのAuthentication
* Mobile and desktop flows(Public client)を有効にする
* API permissions に Microsoft Graph → Delegated で最低限
* Files.ReadWrite(ユーザーのファイルを読み書き)
* offline_access(リフレッシュ/長期トークン)
* User.Read(基本プロフィール)
## ライブラリをインストール
```sh
pip install msal requests
```