在Windows Phone 7.1 C#上使用Google Drive API将图片上传到Google云端硬盘

时间:2015-03-25 17:18:27

标签: c# api windows-phone-8 google-api windows-phone

我是开发Windows Phone应用的新手。此外,我的笔记本电脑太旧了,我无法开发或使用Windows Phone 7.5或更高版本的Emulator,所以我必须坚持使用旧的WP7.1

我想将所选图片上传到Google云端硬盘。我创建了一个用于浏览图像的按钮和一个“图像容器”,以便在选择后显示它。在此处使用以下代码完成。但在显示之后,我希望上传过程也从这里开始。但问题出现在开头。

    private void browseButton_Click(object sender, RoutedEventArgs e)
    {

        PhotoChooserTask photo = new PhotoChooserTask();
        photo.ShowCamera = true;
        photo.Show();
        photo.Completed += new EventHandler<PhotoResult>(browseButton_Click_Conpleted);
    }


    private void browseButton_Click_Conpleted(object sender, PhotoResult e)
    {
        BitmapImage image = new BitmapImage();
        image.SetSource(e.ChosenPhoto);
        displayIMG.Source = image;

        //It works until now

        //Below is the code I copied from many place that will authorize me to upload to their drive.
        string[] scopes = new string[] { DriveService.Scope.Drive,
                             DriveService.Scope.DriveFile};

        UserCredential credential =
                    GoogleWebAuthorizationBroker
                                  .AuthorizeAsync(new ClientSecrets
                                  {
                                      ClientId = "MY_CLIENT_ID_HERE"
                                  ,
                                      ClientSecret = ""MY_SECRET_ID_HERE"
                                  }
                                                  , scopes
                                                  , Environment.UserName
                                                  , CancellationToken.None
                                                  , new FileDataStore("Daimto.GoogleDrive.Auth.Store")
                                                  ).Result;

    }

它显示了很多错误,因为它无法识别某些类型或命名空间,建议不要using。我创建了一个针对WP8.0的新项目,希望它能识别除Environment.UserNamenew FileDataStore之外的所有项目。我已经添加Google.Apis.Drive.v2 client library我不知道我错过了什么。

我的首要任务是在WP7.1上开发。我不想因为这个而买新手机。对不起我的英语。

1 个答案:

答案 0 :(得分:1)

您是否试过PedroLamas示例以便将文件上传到GDrive

相关问题