Xamarin表单上传到谷歌驱动器

时间:2016-08-30 12:07:44

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

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

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

使用Google的基于C#的API Nuget,它们支持基于PCL的项目,API包含Google云端硬盘支持:

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