在 .NET 中開始使用 Google Drive API
以 .NET 程式開發 Google Drive APIs 應用,事前準備工作有:

https://console.developers.google.com/cloud-resource-manager?organizationId=0&authuser=0
點擊 [CREATE PROJECT]

輸入 Project name 與 Location,點擊 [CREATE]






透過下拉選項開窗選擇專案

點擊 [+CREATE CREDENTIALS] -> [OAuth client ID]



下載 OAuth 2.0 Client IDs 檔案


搜尋並加入 Google.Apis.Drive.v3


https://github.com/gsuitedevs/dotnet-samples/blob/master/drive/DriveQuickstart/DriveQuickstart.cs

點擊 [Allow] 後可以關閉瀏覽器

最後取得 Token 會儲存於
C:\Users\Robin\AppData\Roaming\[應用程式指定目錄]
若沒有指定,預設會儲存於
C:\Users\Robin\AppData\Roaming\Google.Apis.Auth
https://developers.google.com/drive/api/v3/quickstart/dotnet
完整的 Google Drive APIs V3 教學影片
https://www.youtube.com/watch?reload=9&v=HZ1qTsH3gXs
- 建立 APIs 專案
- 啟用 Google Drive API
- 輸入 OAuch 授權時顯示的 Application Name
- 建立並下載 Client Secrets 檔案
建立 APIs 專案
進入 IAM & admin > Manage resourcehttps://console.developers.google.com/cloud-resource-manager?organizationId=0&authuser=0
點擊 [CREATE PROJECT]
輸入 Project name 與 Location,點擊 [CREATE]
啟用 Google Drive API
輸入 OAuch 授權時顯示的 Application Name
建立並下載 Client Secrets 檔案
進入 [Credentials]透過下拉選項開窗選擇專案
點擊 [+CREATE CREDENTIALS] -> [OAuth client ID]
下載 OAuth 2.0 Client IDs 檔案
一鍵完成
Google 官方教學網站提供一鍵完成上述動作 [Enable the Drive API]開發 Google Drive APIs 應用程式
Step 1
新增 Console App(.NET Core) 專案,Target framework 選擇 .NET Core 3.0Step 2
NeGet Manage Package搜尋並加入 Google.Apis.Drive.v3
Step 3
加入 client_secrets.json 檔案並設定如下Step 4
參閱 [.NET Quickstart] 原始碼https://github.com/gsuitedevs/dotnet-samples/blob/master/drive/DriveQuickstart/DriveQuickstart.cs
用戶端執行授權
由於是以 Google 一般帳號申請 APIs 專案 (不隸屬任何組織) ,會出現下面警告畫面點擊 [Allow] 後可以關閉瀏覽器
最後取得 Token 會儲存於
C:\Users\Robin\AppData\Roaming\[應用程式指定目錄]
若沒有指定,預設會儲存於
C:\Users\Robin\AppData\Roaming\Google.Apis.Auth
參考連結
.NET Quickstart 範例https://developers.google.com/drive/api/v3/quickstart/dotnet
完整的 Google Drive APIs V3 教學影片
https://www.youtube.com/watch?reload=9&v=HZ1qTsH3gXs