OneDrive API 瀏覽器 C# (OneDrive API browser C#)


問題描述

OneDrive API 瀏覽器 C# (OneDrive API browser C#)

好的,所以我決定將 onedrive 功能集成到我的項目中,我已按照此處列出的說明進行操作:https://github.com/OneDrive/onedrive‑sample‑apibrowser‑dotnet

我已經設置了需要設置的變量,更新了所有的nuget庫,註冊應用程序並設置讀寫等所需的權限。

private const string AadClientId = "6b18d325‑####‑####‑####‑##########b0";
private const string AadReturnUrl = "http://localhost:44313";
private const string MsaClientId = "6b18d325‑####‑####‑####‑##########b0";

一切似乎都在工作到最後的登錄點。項目編譯,我點擊“登錄到 aad”我知道這部分是正確的,因為登錄頁面出現在登錄框上方我註冊的應用程序標題。詳細信息輸入正確,它會通知您它正在登錄並重定向您並繼續到標題為“繼續”的空白頁面,一切似乎都設置正確並正常進行,但隨後遇到障礙並返回一個消息框“身份驗證失敗”,詳細異常說明:AADSTS50001: The application named http://localhost:44313 was not found在名為 9188040d‑####‑####‑####‑##########ad 的租戶中。如果租戶管理員未安裝應用程序或租戶中的任何用戶未同意此應用程序,則可能會發生這種情況。您可能將身份驗證請求發送給了錯誤的租戶。

我讀到我可能需要在 AzureAD 中做一些事情,但我不確定,以前從來沒有用一個驅動器做過任何事情,所以任何幫助我解決這個問題的幫助都會很棒!

謝謝大家!問候詹姆斯


參考解法

方法 1:

Registering an app on the Microsoft registration portal gives it access to the consumer version of OneDrive (in the demo, you access it by "Sign in to MSA") ‑ that one should work for you, unless you've also set the MsaReturnUrl to be localhost (in which case, change it to the one originally in the sample). You'll be able to log in with your Live ID and access your OneDrive data.

The business version uses an Azure Active Directory you set up yourself, on Azure. Once you have one, that's where you'll be registering your application, adding users, and accessing the ClientId you'll eventually need to put into the code.

This is probably out of scope for this question ‑ if you simply want to use personal OneDrive accounts, then use the MsaAuthenticationProvider and don't worry about those Aad... properties and the AdalAuthenticationProvider.

方法 2:

Here you go. it create application and secret in Azure portal with few clicks. https://developer.microsoft.com/en‑us/graph/quick‑start

Please select the type of application that you want to create. Next click is automated to create application, other things in azure portal on behalf of us.

 IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
       .Create(ClientId)
       .WithTenantId(TenantID)
       .WithClientSecret(ClientSecret)
       .Build();

        ClientCredentialProvider authProvider = new **ClientCredentialProvider**(confidentialClientApplication);
        GraphServiceClient _graphClient = new GraphServiceClient(authProvider);

please change the auth provider accordingly. the current one is for authenticating application identity(with secret generate in Azure against application).

(by user3564069Maciej StachowskiBhaskar Reddy)

參考文件

  1. OneDrive API browser C# (CC BY‑SA 2.5/3.0/4.0)

#onedrive #API #C#






相關問題

WP7-Skydrive API 下載任何文件並保存隔離存儲 (WP7-Skydrive API Download Any file and Save Isolated Storage)

如何編寫 .NET 控制台應用程序來訪問 SkyDrive? (How can I write a .NET console application to access SkyDrive?)

Loại đăng nhập Skydrive API Windows 8 (Skydrive API login type Windows 8)

如何使用 Rest api 和 oauth2.0 創建文件夾和上傳文件 (How to create folder and upload file using Rest api and oauth2.0)

從 ERP 保存到 OneDrive (Save to OneDrive from ERP)

適用於 Windows 通用 APP 的 OneDrive Api (OneDrive Api for Windows Universal APP)

一種 Drive / Office365 與 Google Apps Script 類似的腳本語言 (One Drive / Office365 similar scripting language as the Google Apps Script)

OneDrive API 瀏覽器 C# (OneDrive API browser C#)

從 Python 應用程序訪問 Microsoft Live 服務 (Access Microsoft Live services from Python application)

一個驅動器 api 安全 URL (One drive api secure url)

嘗試使用 get-PnPFile 從 OneDrive 獲取文件的所有版本時找不到文件 (File not found trying to get all versions of a file from OneDrive using get-PnPFile)

一個驅動器遷移 (One Drive Migration)







留言討論