【问题标题】:Xamarin forms upload to google driveXamarin 表单上传到谷歌驱动器
【发布时间】:2019-05-14 22:25:27
【问题描述】:

在我的 Xamarin 表单应用程序中,我需要将 zip 文件上传到谷歌驱动器。是否可以使用 Xamarin 表单应用程序执行此操作?我是否需要使用依赖服务在每个平台上实现它?请给我一个合适的建议。

【问题讨论】:

    标签: xamarin xamarin.ios xamarin.android xamarin.forms


    【解决方案1】:

    我想你必须创建一个REST 服务才能使用Google Drive API,当然你还必须管理authentication

    【讨论】:

      【解决方案2】:

      使用 Google 基于 C# 的 API Nuget,它们支持基于 PCL 的项目,并且 API 包含 Google Drive 支持:

      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" />
      

      来自 Google 的云端硬盘示例:

      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);
      

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

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多