【问题标题】:Xamarin Form - How to upload,Delete,Download Files From Google Drive in UWPXamarin Form - 如何在 UWP 中从 Google Drive 上传、删除、下载文件
【发布时间】:2019-10-09 21:10:43
【问题描述】:

您好朋友,我想在 Google 云端硬盘上上传图片、文件。所以我已经安装了Google.Apis.AuthGoogle.Apis.Drive.v3 nuget 包。

我还通过引用视频https://www.youtube.com/watch?v=xtqpWG5KDXYNow 创建了Client_secrete.json 文件。问题,如何使用这个Client_secrete.json 文件并从uwp 的Google Drive 中上传、下载、删除文件? :(

任何想法然后请分享代码或链接。

提前致谢:)...

  public static DriveService GetService()
    {
        UserCredential credential;
        DriveService service = new DriveService();
        using (var stream = new FileStream(destinationFolder.Path + @"\client_secret.json", FileMode.Open, FileAccess.Read))
        {
            String FolderPath = destinationFolder.Path;
            String FilePath = Path.Combine(FolderPath, 
"DriveServiceCredentials.json");
            credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                GoogleClientSecrets.Load(stream).Secrets,
                Scopes,
                "users",
                CancellationToken.None,
                new FileDataStore(FilePath, true)).Result;   // Here i got 
the exception.

            service = new DriveService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName = "DemoDrive",
            });

        }
        return service;

    }

当我尝试运行此代码时,它会出错。 :(如何解决这个.....

【问题讨论】:

    标签: xamarin.forms uwp win-universal-app uwp-xaml


    【解决方案1】:

    请检查Google.Apis.Drive.v3,nuget包不兼容平台包含uwp和Xamarin。因此,您不能将它用于 xamarin.uwp 应用程序。 uwp平台内的云盘,建议使用OneDrive替换。并且我们提供了OneDrive Service api,可以立即实现云驱动。

    【讨论】:

    • 感谢您的宝贵回复。 link 那么这个谷歌誓言样本有什么用?如果我想将我的数据存储在谷歌驱动器上怎么办?他们有第三方 dll 吗?
    • @ketan,这个案例reply 可能会有所帮助。
    • OneDrive 对 UWP windows 应用程序的支持?如果支持,请分享一些代码或链接。我应该安装哪个 nuget 包?谢谢你:)
    • 请检查此代码示例link。请安装Microsoft.Toolkit.Uwp nuget 包。
    • 你有没有其他代码示例我不明白上面的链接:(
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-14
    • 1970-01-01
    • 2021-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多