KoenZomers / OneDriveAPI

API in .NET Framework 4.8.0, .NET Core 3.1 and .NET 6.0 to communicate with OneDrive Personal and OneDrive for Business
Eclipse Public License 1.0
110 stars 34 forks source link

How to get driveitem from public folder or file? #16

Closed Pilzinsel64 closed 5 years ago

Pilzinsel64 commented 5 years ago

Hello!

This isn't realy a issue, but I realy don't know how to get a DriveItem from a public file like this. Or, how can I get a DriveItem from a public folder?

Thanks

Pilzinsel64

Pilzinsel64 commented 5 years ago

Hello again!

Now it is an issue. I tried to get the direct download like: https://onedrive.live.com/download?cid=025EBB683889A2B9&resid=25EBB683889A2B9!1396&authkey=AJxFQ8726d8On94 It works, but when I call OneDriveGraphApi.GetItemFromDriveById("25EBB683889A2B9%211396", "25EBB683889A2B9") I get this exception. Probably because it needs my authkey (AJxFQ8726d8On94) for this file, but there is no way to do that.

System.NullReferenceException HResult=0x80004003 Nachricht = Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt. Quelle = KoenZomers.OneDrive.Api Stapelüberwachung: bei KoenZomers.OneDrive.Api.OneDriveApi.d134.MoveNext() bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) bei KoenZomers.OneDrive.Api.OneDriveApi.d132.MoveNext() bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) bei KoenZomers.OneDrive.Api.OneDriveApi.d131`1.MoveNext() bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) bei KoenZomers.OneDrive.Api.OneDriveApi.d1251.MoveNext() bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) bei KoenZomers.OneDrive.Api.OneDriveApi.<GetItemFromDriveById>d__73.MoveNext() bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) bei System.Runtime.CompilerServices.TaskAwaiter1.GetResult() bei WindowsApp1.Form1.VB$StateMachine_8_LetsGo.MoveNext() in C:\Users\Pascal2\source\repos\WinConTests\WinConTests\Form1.vb: Zeile39

KoenZomers commented 5 years ago

The API is not designed to work with anonymous sharing links other than creating them. Why would you want to revert it to a DriveItem?

Pilzinsel64 commented 5 years ago

I want to download files (e.g. for updater) in my tool and I don't want to put my encrypted account informations in this tool just do download shared files.

However, I've found a workaround by modifying the links for embeding files to be (direct) download links. Then I can download them via System.Net.WebRequest.

Embedded link: https://onedrive.live.com/embed?cid=025EBB683889A2B9&resid=25EBB683889A2B9%211469&authkey=ALgRKMKtYWAC0cU

Download Link: -> Change "embed" to "download" https://onedrive.live.com/download?cid=025EBB683889A2B9&resid=25EBB683889A2B9%211469&authkey=ALgRKMKtYWAC0cU

A feature to do this in your api still would be nice.

KoenZomers commented 5 years ago

So if I understand you correctly, you would like to see support added in the API to perform this operation:

https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_preview?view=odsp-graph-online

Which effectively would return you the embed link which you can transform into a download link.

Correct?

KoenZomers commented 5 years ago

Closing due to no response received.