I looked for a solution in Google about using Google Drive API in UWP.
I saw this article, and the accepted solution is short – doesn’t work as it is in UWP apps.
I tried to create a new class and it did work.
//StorageFile tempfile = Credentials location
var credential = GoogleCredential.FromFile(tempfile.Path)
.CreateScoped(new[] { DriveService.ScopeConstants.DriveFile });
var service = new DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "App name"
});
after that, I could use Drive API to upload and download. All I needed to do – was make everything as Task.
For example –
using (var stream = tempfile.OpenStreamForReadAsync().Result)
{
var request = service.Files.Create(fileMetadata, stream, "application/octet-stream");
request.Upload();
var uploadedFile = request.ResponseBody;
Debug.WriteLine($"File uploaded: {uploadedFile.Name} ({uploadedFile.Id})");
}
I used .Result
and .AsTask().Wait()
instead of await
and AsTask().Result
in any function.
Did it work only in debug? or now it supports?
sorry about my English
Never used UWP, so no idea if that will cause any issues, but I wrote a package to ease the (considerable) pain when using Google Drive. There’s a Nuget package available for it. Maybe see if that helps.
The Google API dotnet client library doesn’t support up authorization
@LindaLawton-DaImTo well, I just succeeded in uploading a file and downloading it in UWP and google.drive.api.v3
@AvrohomYisroel this package work on uwp?