0

In my Xamarin forms application I need to upload a zip file to google drive.Is it possible to do this using Xamarin forms application? Do I need to implement this in each platform using dependency services? Please give me a proper suggestion.

Aneesh.A.M
  • 1,128
  • 4
  • 17
  • 35

2 Answers2

0

I'd imagine you'd have to create a REST service to make use of the Google Drive API, of course you'd have to manage authentication as well.

Rokuren
  • 101
  • 8
-1

Use Google's C#-based API Nuget, they support PCL-based projects and the API contains Google Drive support:

Xamarin.Forms:

<package id="Google.Apis" version="1.16.0" targetFramework="portable45-net45+win8+wp8" />

Xamarin.Android:

<package id="Google.Apis" version="1.16.0"    targetFramework="monoandroid60"` />

Xamarin.iOS:

<package id="Google.Apis" version="1.16.0" targetFramework="xamarinios10" />

From Google's Drive Sample:

GoogleWebAuthorizationBroker.Folder = "Drive.Sample";
UserCredential credential;
using (var stream = new System.IO.FileStream("client_secrets.json",
    System.IO.FileMode.Open, System.IO.FileAccess.Read))
{
    credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
        GoogleClientSecrets.Load(stream).Secrets, Scopes, "user", CancellationToken.None);
}

// Create the service.
var service = new DriveService(new BaseClientService.Initializer()
{
    HttpClientInitializer = credential,
    ApplicationName = "Drive API Sample",
});

await UploadFileAsync(service);

Ref: https://developers.google.com/api-client-library/dotnet/apis/drive/v3

SushiHangover
  • 73,120
  • 10
  • 106
  • 165
  • I couldn't find Google.Apis.Auth in the package – Aneesh.A.M Aug 31 '16 at 09:12
  • Could you share any sample project? – Aneesh.A.M Sep 02 '16 at 06:26
  • I couldn't find GoogleWebAuthorizationBroker http://stackoverflow.com/questions/22456668/googlewebauthorizationbroker-not-found – Aneesh.A.M Sep 02 '16 at 06:51
  • Google's .NET client does not support Xamarin. See: https://github.com/googleapis/google-api-dotnet-client/issues/1468 and https://github.com/googleapis/google-api-dotnet-client/blob/master/FAQ.md#why-arent-unity-xamarin-or-uwp-supported – Mr.Yeah Nov 13 '19 at 14:50
  • @Mr.Yeah The OP question is about uploading to GDrive and it does work, they are .NetStd-based : https://www.nuget.org/packages/Google.Apis.Drive.v3 After 3 years I still use it. – SushiHangover Nov 13 '19 at 15:20
  • @SushiHangover Then I don't get why Google explicitly says that it's incompatible with Xamarin. – Mr.Yeah Nov 14 '19 at 13:44
  • 1
    @Mr.Yeah The Auth portion of their Drive .Net solution is natively attached to Windows, but it is just OAuth2 so you can roll your own. All their APIs (iOS|Android|.Net|...) use their underlaying REST (which is an option to use directly also). – SushiHangover Nov 14 '19 at 15:16